- Home /
Waypoint Coliider Error
Error message: gameObject is not a member of 'UnityEngine.Collider[]
Im going through a tutorial teaching me how to do waypoint AI pathing.
Heres all my code, Ive heard there can be issues will calling a GameObject, did I miss type something?
var neighbors:Collider[];
function Update () {
}
//the function to receive data
var countdown: int = 3;
function setData(incomingData)
{
countdown = incomingData;
countdown --;
Debug.Log("the waypoint " + this.name + " sent the countdown of " + countdown);
sendData();
}
function sendData ()
{
if (countdown > 0)
{
for (var neighbor in neighbors)
{
neighbors.gameObject.GetComponent(Waypoint).setData(countdown);
}
}
}
//the function that sends data to the neighbors
var mask : LayerMask = 1 << 8;
var sphereDistance: int = 10;
private var breakWhile: int = 1;
function Awake () {
while (neighbors.Length < 3 && breakWhile < 10){
neighbors = Physics.OverlapSphere(transform.position,sphereDistance,mask);
sphereDistance += 10;
breakWhile ++;
}
}
What compiler errors are you getting, cause what stands out to me is your not type casting (IE i want this variable to of this type... further IE, var myInt : int = 1, where int is the type and var is the reciever of that type or the one its being cast to) the setDate variable so the inco$$anonymous$$gData. That seems to be the biggest thing standing out to me, but in future posts if you could also include the error your getting it would be a big help!
Answer by robertbu · Feb 20, 2014 at 05:56 AM
You don't list the line number of the error, but it has to be line 22. You should be using 'neighbor' not 'neighbors' in this line.
neighbor.gameObject.GetComponent(Waypoint).setData(countdown);
That is the for() loop is pulling out each entry in the array one at a time and assigning that one for the current iteration to 'neighbor'. That single collider is what you should be referencing.