Hello! I am struggling to find a way to make my enemy have the same direction after it respawns. It has no rigdbody. I tried to get the initial speed of the all my enemies and put that value in the for of a float array. The problem is that I have the speed value of all my enemies in another script. Would appreciate help. Here is what I tried: ( I only put the essential parts of each scripts)
First script:
public GameObject[] enemies;
public float[] InitialDirection { get; set;}
public class Interwithenemy : MonoBehaviour
{
void Start()
{
InitialDirection = new float[enemies.Length];
for (int i = 0; i < enemies.Length; i++){
InitialDirection _= Normalenemy.speed*; // this line shows error at the last part*_
}
}
Second Script:
public class Normalenemy : MonoBehaviour{
public float speed;
}
I guess that all your enemies have the script called “Normalenemy” as component attached.
That should fix your error in the mentioned line.
InitialDirection _= enemies*.GetComponent<Normalenemy>().speed;*_
But this way you get only the speed value and not any initial direction. A direction is either 2D-Vector or a 3D-Vector.
You should watch some basic tutorial videos to the get an idea of the basic API functions that unity offers. E.g. how to access scripts attached to gameobjects with GetComponent().
[Turorial - GetComponent][1]
_*[1]: https://unity3d.com/learn/tutorials/topics/scripting/getcomponent*_