Change something in this script

Hey Guys, like my name, i’m brazilian :stuck_out_tongue: so i don’t speak english so good ( I’m not using google translator).Sorry if I wrong something.

anyway i want to change somethings in this script :

    var cube : Transform;

    var gutext : GUIText;

    function Update () {

    var dist : float = Vector3.Distance(cube.position, transform.position);


    gutext.text="Look Out!";







I want to change the “Transform” to “Tag”.
the name of this tag is “enemy”

I assume that you’re trying to get the distance between a cube and a GameObject tagged “enemy”, so I believe you should do the following:

var dist : float = Vector3.Distance(cube.position, GameObject.Find("enemy").transform.position);

You can look for gameobjects using that function, and each transform belongs to a gameobject. I also suggest you place the GameObject.Find() outside of the Update() function, for performance reasons.

If I am right in guessing you want to create a distance between two objects, your cube and your enemy? Try this:

var dist : float = Vector3.Distance(cube.position, gameObject.FindWithTag("Enemy").transform.position);

Like so Link to the unity docs

I hope this helps!