I need to know how to enable the text “1/4 Notes Collected” when I left click on a sheet of paper. The paper already makes it’s sound and destroy’s when I click it. Now all I need to do is have the text listed above show for 3 seconds. In js, how would I do this? Here’s my script. (It’s very messy, I had a friends help me with it)
var information: String;
private var guiOn = false;
private var rect: Rect;
function OnMouseDown(){
guiOn = true;
rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
yield WaitForSeconds(3);
guiOn = false;
}
function OnGUI(){
if (guiOn){
GUI.Label(rect, information);
}
}
I’m guessing that script is attached to the same game object as the one that is being destroyed. That’s your problem - you are destroying it and still trying to use OnGUI on it! So you need to not destroy it until after 3 seconds to give the GUI time to show. You might just want to turn the renderer and collider off before that.
renderer.enabled = false;
collider.enabled = false;
This will work if it’s just one object - if it is itself the parent of other objects then you will have to get all of them:
foreach(var r : Renderer in GetComponents(Renderer))
{
r.enabled = false;
if(r.collider)
r.collider.enabled = false;
}
This will work if all of your colliders are on objects with renderers - otherwise you would need a second for loop for the colliders.