I am trying to access a Transform array from a scene object to give to my prefab. I searched the forums and found a solution for a single variable. I tried to use what they had to work with what I need but couldn’t get it to work. Here is the script called “MinionSpawn” that is attached to the scene object. I attach the Transform points in Unity.
MinionSpawn.cs
public Transform[] waypoints;
Here is the script called “Minions” that I am trying to use the array in. The array is 14 waypoints that each instantiate minion prefab will use to navigate the map.
Minions.cs
public class Minions : MonoBehaviour {
int currentWaypoint = 0;
public float minionSpeed = 20;
private MinionSpawn minionSpawn = FindObjectOfType(typeof(MinionSpawn));
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Transform[] waypoints = minionSpawn.waypoints;
float amtToMove = minionSpeed * Time.deltaTime;
if (currentWaypoint < waypoints.Length)
{
Vector3 target = waypoints[currentWaypoint].position;
Vector3 moveDirection = target - transform.position;
transform.LookAt(target);
transform.Translate(Vector3.forward * amtToMove);
if (moveDirection.magnitude < 1)
{
currentWaypoint++;
}
}
else
{
transform.Translate(new Vector3(0,0,0));
}
}
}
In its current state I am getting the following error: Cannot implicitly convert type ‘UnityEngine.Object’ to ‘MinionSpawn’. An explicit conversion exists (are you missing a cast?)