0

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);

}
8
  • I forgot to tell you something after answering your last question. UnityScript/Javascript is no longer supported. The compiler will be removed soon. You have to learn and start using C#. Commented Aug 26, 2017 at 13:00
  • As for your problem, you need to add another ) before the {. Also that code in the if statement should be inside a function. It's not inside a function right now. Commented Aug 26, 2017 at 13:01
  • @Programmer can you please give me an example Commented Aug 26, 2017 at 13:04
  • Sure I will but won't in the future if you keep asking js questions with Unity. Your counter variable is not declared too. What is the name of that class? Commented Aug 26, 2017 at 13:08
  • the script class is counter.js counter.water --> water = variable Commented Aug 26, 2017 at 13:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Tanks for the help i have make a new script for the score system but in c# so now i will remake all js in to c# its sounds more easy
Yes. I suggest you do that now that you have few scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.