ines
ines

Reputation: 117

Read mouse click Input.GetMouseDown with Unityscript

I try to get on the mouse down work, I have find a example but its not work this is my error Assets/scripts/onclickx.js(13,5): BCE0044: expecting EOF, found '}'.

This is my code

import UnityEngine.UI;
import UnityEngine.EventSystems;



if(Input.GetMouseDown(0){
   // Whatever you want it to do.
   ScoreSystem.drinks -= 1;

   mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
   counter.water = counter.water += 10
  mySlider.value = counter.water; 
}

this is the script for the counter.js

import UnityEngine.UI;
var mySlider: UnityEngine.UI.Slider;
var water = 90;
function Start () {
  // substitute 'sliderName' with the literal name 
  // of your slider as it appears in the hierarchy:
  mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
  mySlider.value = water; 
  }


 function OnTriggerEnter(other : Collider) 
 {
        Destroy(gameObject);
        ScoreSystem.drinks += 1;
        mySlider.value += 10; 
  // insert desired variable here in place of 'n'
  // slider will automagically adjust to display new value
  }

and this is the code for my score system

static var myScore = 0;
static var score = 0;
static var money = 0;
static var level = 0;
static var drinks = 0;


public var guiSkin : GUISkin;




function OnGUI()
{
 GUI.skin = guiSkin;

GUI.contentColor = Color.green;

GUI.Label(Rect((Screen.width / 2) - 60,15, 200, 30), "Score: " + score);
GUI.Label(Rect((Screen.width / 2) - 60,30, 200, 30), "Money: " + money);
GUI.Label(Rect((Screen.width / 2) - 60,42, 200, 30), "Level: " + level);
GUI.Label(Rect((Screen.width / 2) - -320,25, 200, 30), "Drinks: " + drinks);

}

Upvotes: 0

Views: 92

Answers (1)

Programmer
Programmer

Reputation: 125425

There are just many issues with your first code.

1.The code is not inside a function. That should be in the Update function.

2.You are missing extra ) in the if statement since there should be one ) for the GetMouseDown function and another one that closes the if statement.

3.The mySlider variable is not declared. You manged to declare that in the counter script but not in your first script.

import UnityEngine.UI;
import UnityEngine.EventSystems;

var mySlider:Slider;

function Update(){

    if(Input.GetMouseDown(0)){
        // Whatever you want it to do.
        ScoreSystem.drinks -= 1;

        mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
        counter.water = counter.water += 10;
        mySlider.value = counter.water; 
    }
}

Note:

It is always good to capitalize the first letter in your class/script name. For example, counter should be Counter and your variable names should start with lower-case. This will make it easier for people to read and understand your code.

Finally, convert all your scripts to C#. You will have to do this ASAP so that you won't have to restart your project over again when the Unityscript compiler is removed.

Upvotes: 1

Related Questions