My script is behaving too early when clicked. Here’s my code:
var targetScript : ChangeSprite;
var AcceptInput : boolean = true;
private static var score : int = 0;
var guiScore : GUIText;
function Start ()
{
guiScore.text = "Score: 0";
}
function OnMouseDown () {
if(AcceptInput)
{
AcceptInput = false;
}
targetScript = GameObject.Find("Shape").GetComponent(ChangeSprite);
GameObject.Find("Shape").GetComponent(ChangeSprite).enabled = true;
Debug.Log("Clicked");
if(targetScript.spriteRenderer.sprite == targetScript.diamond) {
score += 1;
guiScore.text = "Score: " + score;
}
else{
Debug.Log("Wrong Answer!");
}
}
function OnMouseUp () {
AcceptInput = true;
GameObject.Find("Shape").GetComponent(ChangeSprite).enabled = false;
}
It changes the sprite too early. When I press the button it would add the score before it even displayed the sprite. Any ideas? Any help would be much appreciated. Thanks