Firstly, heres my code:
var target : StartSprite;
var targetScript : ChangeSprite;
var AcceptInput : boolean = true;
private static var score : int = 0;
var guiScore : GUIText;
function Awake () {
function OnMouseDown () {
if(!AcceptInput)
{
return;
}
AcceptInput = false;
if(target.spriteRenderer.sprite == target.diamond) {
score +=1;
guiScore.text = "Score: " + score;
yield WaitForSeconds (0.5);
targetScript.enabled = true;
}
else {
yield WaitForSeconds (0.5);
targetScript.enabled = true;
Debug.Log("Wrong Answer");
}
}
function OnMouseUp () {
AcceptInput = true;
targetscript.enabled = false;
changeSprite ();
}
}
}
function changeSprite (){
function OnMouseDown () {
if(!AcceptInput)
{
return;
}
AcceptInput = false;
if(target.spriteRenderer.sprite == target.diamond) {
score +=1;
guiScore.text = "Score: " + score;
yield WaitForSeconds (0.5);
targetScript.enabled = true;
}
else {
yield WaitForSeconds (0.5);
targetScript.enabled = true;
Debug.Log("Wrong Answer");
}
function OnMouseUp () {
AcceptInput = true;
targetscript.enabled = false;
changeSprite ();
}
}
}
Theres a compiling error with nested functions. I searched this up on the internet. I heard that you can’t use nested functions in unityscript. I’m a newbie to this. Does anyone have anyway to make the same effect? I really don’t know what to do. What’s an alternative to nested functions?