public class WayPoint: MonoBehaviour { Transform[ ] waypoint; int currentWayPoint;
void Start ()* { waypoint[0] = GameObject.Find(“WP0”).transform; // Here waypoint[1] = GameObject.Find(“WP1”).transform; // herre waypoint[2] = GameObject.Find(“WP2”).transform; // and Here
}* }
when i "play " the game, i have a alert message : “Assets/Scripts/WayPoint.cs(5,17): warning CS0649: Field WayPoint.waypoint' is never assigned to, and will always have its default value null’” (it is the Transform[ ] waypoint; line)
when i create a new instance of my class, i have a error message “Array index is out of range.” (for the 3 “//here” lines)
What is the problem ? i suppose it is a stupid error i did, but where ? (i dont want a fixed size (3) Array, i juste have 3 waypoint here, but it will be random later)
Your array is null. In the Start try getting all the waypoints (use a tag for them and find objects by tag) and use that array (array of gameobjects) or use that count to instantiate your array of transform, then loop the found objects to assign the transforms