How to display a cloud dialog in Unity?

0

You see, I'm doing a game in Unity but I do not know how to make the Script to make a little cloud appear on top of the character, I already have the texture of the cloud but I want to make the cloud appear when I get close and always look at If you know how to do it, could you explain the structure?

    
asked by DSRaptor DEV 02.10.2018 в 21:57
source

1 answer

0

This would be a way to do it. For example, I put the name of the tag as Activator, but you can also do it with a name, putting the name of the gameobject that activates it.

Code:

...
using UnityEngine.UI;

public GameObject Nube;

void OnCollisionEnter2D(Collision2D coll){ 
if(coll.gameobject.tag == "Activador")   // El nombre del tag es el que le pusiste al                                     
{                                        // GameObject, también lo puedes hacer con 
                                         // name
 Nube.SetActive(true);                      
}
} 
void OnCollisionExit2D(Collision2D collexit){
if(collexit.gameobject.tag == "Activador")
{
Nube.SetActive(false);
}
}
}

What this code does is simply that it activates the cloud when it touches the Collider and when it goes out it deactivates it. (The cloud you have to put on the canvas as an image) (Keep in mind put the limit sprite, that's where you want the cloud to be activated) Hope this can help you. Greetings.

    
answered by 02.10.2018 / 22:13
source