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

}
Programmer
  • 121,791
  • 22
  • 236
  • 328
ines
  • 117
  • 10
  • I forgot to tell you something after answering your last question. UnityScript/Javascript is [no longer](https://stackoverflow.com/a/45536613/3785314) supported. The compiler will be removed soon. You have to [learn](https://unity3d.com/learn/tutorials/s/scripting) and start using C#. – Programmer Aug 26 '17 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. – Programmer Aug 26 '17 at 13:01
  • @Programmer can you please give me an example – ines Aug 26 '17 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? – Programmer Aug 26 '17 at 13:08
  • the script class is counter.js counter.water --> water = variable – ines Aug 26 '17 at 13:27
  • Is the water a static variable? It is better to post that script too. – Programmer Aug 26 '17 at 13:31
  • @Programmer Yes it his a static variable – ines Aug 26 '17 at 13:35
  • You gotta be start to learn C# because c# is 4x faster than javaScript – amdev Sep 12 '17 at 07:41

1 Answers1

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.

Programmer
  • 121,791
  • 22
  • 236
  • 328