Hello guys,
I have been searching how to display a message replacing the Debug.Log (code below) for a GUI during 2 seconds and then hide it. The research conducted has pointed out that I should create a boolean but when I try with the following code, I have an error that says "Return type ‘void’ cannot be used on a generator. Did you mean ‘IEnumerator’? You can also use ‘System.Collections.IEnumerable’ or ‘object’… " Also, the object clicked is not destroyed.
Thank you in advance for your help.
var object: GameObject;
var information: String = "Well done";
var guiOn = false;
private var rect: Rect;
function OnMouseDown():void
{
var clickedTag:String = gameObject.tag;
if(Inventory.objectToBeFound == 1) selected = true;
guiOn = true;
rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
yield WaitForSeconds(5);
guiOn = false;
start.score += 100;
Debug.Log("Well done!");
Destroy(gameObject);
if(Inventory.objectToBeFound != 1) {
Debug.Log("incorrect object");
}
}
function OnGUI(){
if (guiOn){
GUI.Label(rect, information);
}
}
Answers should be reserved for potential answer to your question. Use the "add new comment" button below your question to add new material. As for your problem. You destroy your game object on line 21, so the rest of your code will not execute. I'm not sure what you want to happen in case the Inventory.objectToBeFound != 1, but at the very least you need to be the Destory() below your second if statement to get this code to work.
– robertbuI didn't know about the potential answers, sorry. I have removed the Destroy() from line 21, as you recommended. Related to the Inventory.objectToBeFound != 1, if the object clicked is not object number 1 but 2 or 3 (other objects inside the array) I want a display message again which says "Object incorrect".
– Lasset