Im at a stump because I have had a problem with functions like GetComponent();.
this is a simple example script for reference:
var myTransform : Transform;
function Update () {
transform.LookAt(myTransform);
}
The script works fine for making my enemies face the player, and all is good. I place the enemy in the scene, attach the script, and set the transform to my player and play it.
What the problem is however, Is I cannot have additional enemies spawn into the scene because The transform will be blank, so the enemy will just shoot at a wall. And having to have every enemy and object on the map have to be pre assigned is tiresome, time consuming and limits thegames capabilities.
What I am wondering, is how to make the first line of the script, or any function looking like this:
var HPtext : GUIText = gameObject.GetComponent(GUIText);
be able to reference an object and target it without having to be pre assigned. How would I go about doing this?
↧