- Home /
GUIText spawning when gameobject is destroyed.
I'm sorry if this has been posted before. I've searched for hours and haven't been able to find it. I'll try to be as direct as possible.
I have a GUIText that looks perfect, it appears, it floats up and it disapears. The only problem is that it spawns when the game begins. I need this GUIText to stay inactive until a spicific game object (cube) is destroyed (collected by the character).
This is the scrip for the GUIText, now I just need help with the next step.
#pragma strict
public var color: Color = Color(0.8,0.8,0,1.0);
public var scroll: float = 0.05;
public var duration: float = 1.5;
public var alpha: float;
function Start(){
guiText.material.color = color;
alpha = 1;
}
function Update(){
if (alpha>0){
transform.position.y += scroll*Time.deltaTime;
alpha -= Time.deltaTime/duration;
guiText.material.color.a = alpha;
} else {
Destroy(gameObject);
}
}
If anybody can give me a hand with this, it'll be of great help. Thank you.
Answer by Bunnybomb7670 · Mar 13, 2014 at 12:17 AM
This function : https://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnDestroy.html may be useful,it is called just before and object is destroyed, you can use that function to spawn you're text object.
Your answer
![](https://koobas.hobune.stream/wayback/20220613140115im_/https://answers.unity.com/themes/thub/images/avi.jpg)