Hey, First time posting for help. I guess that means I’m doing better than I thought, haha!
I’m trying to run a method on all tagged “Minions” at the same time, but even though I beleive I’m declaring them correctly, it’s throwing “An object reference is required for the non-static field, method, or property ‘Waypoints.minion’” at me.
Here’s my code.
using UnityEngine;
public class Waypoints : MonoBehaviour
{
public static Transform[] points;
public static Transform goal;
//starts at 1 since Spawn is 0
public static int counter = 1;
MinionController minion;
GameObject[] minions;
void Awake ()
{
points = new Transform[transform.childCount];
for (int i = 0; i < points.Length; i++)
{
points[i] = transform.GetChild(i);
}
}
void Update ()
{
goal = points[counter];
}
public static void WaypointReached()
{
counter++;
GameObject[] minions = GameObject.FindGameObjectsWithTag("Minion");
for (int i = 0; i < minions.Length; i++)
{
minion = minions[i].GetComponent<MinionController>();
minion.Celebrate();
}
}
}
It’s the 2 minion lines at the bottom that are giving me grief. Both of them think they need an object reference.
I also tried the suggested outline in the unity API and got the same thing.
public static void WaypointReached()
{
counter++;
GameObject[] minions = GameObject.FindGameObjectsWithTag("Minion");
foreach(GameObject minion in minions)
{
minion.Celebrate();
}
}
Any thoughts?
Let me know if anyone needs the MinionController class.