GameObject A needs GameObject C from GameObject B - Noob Question

Hey Guys,
I just moved from C# and XNA to Unity and am reproducing one of my older projects to get started and learning. My question is kind of a noob question (but I didn’t know how to properly search it - the keywords return too many results :-/ ). So here’s my goal:
I have a network of streets with several crossings in which AI-controlled cars should drive around. Therefor I created a Waypoint GameObject which consists of nothing more than it’s position and an array of following waypoints (stored in a script-component, if that is of importance). Now my cars move to their starting waypoint (defined with the inspector) and as soon as they get close to it they should choose one of the following waypoints defined in the current waypoint. So in conclusion the car (A) querys its new Waypoint (C) from its current waypoint (B).
In short: I’ve got no idea how to do this.
Any hints (also on documentation / tutorials) would be appreciated.
Thanks,
Daniel

Since your initial waypoint is known to the vehicles, you would use GetComponent() to get the script component containing the array of waypoints.

WaypointScript points = waypoint.GetComponent<WaypointScript>(); // Or whatever waypoint and your script type are.

And, just remember, script components are classes. i.e. Define multiple Monobehaviour classes in a single script, each of those classes should be available as a script component.

Unless your Waypoint Object is arealy assigned, find the Waypoint Object via GameObject.Find, GameObject.FindGameObjectWithTag, or whatever tickles your fancy. Then use GetComponent to grab the script object off of your Waypoint Object and grab the other waypoints from there.

Probably a good idea to take a peak at GameObject in the Scripting Reference.

Thanks so far! Here’s what I tried in the cars script:

WPBehaviour wpB = currentWP.GetComponent<WPBehaviour>();

Which results in returning null =/
I’m sorry if this is a dumb question, but I feel like I did what the video-tutorial says…

It’s returning null because it isn’t finding a component of type WPBehaviour attached to currentWP. Maybe post code and a screenshot/snip of the waypoint object being shown in the inspector?

Here we go:
1374655--69468--$WPInspector[1].PNG
This is the Waypoint. The Code (right now) only contains the definition for the GameObject[ ] nextWPs. I add those next waypoints manually to a waypoint using the inspector.
The car uses this code in it’s update-method:

void Update () 
{
	Speed = currentWP.transform.position - this.gameObject.transform.position;
	Speed.Normalize();
	Speed *= 0.5f;
	this.gameObject.transform.position += Speed;
	if(Vector3.Distance(this.transform.position, currentWP.transform.position) < 1f)
	{
		WPBehaviour wpBehaviour = currentWP.GetComponent<WPBehaviour>();	
		//and whatever should follow
	}		
}

Let me know if you need any further information.
Thanks!

Ok, I don’t really have a clue why, but it works now (using the code written above). Might have been something mixed up with prefabs and Scripts used in the GameObject itself. Frankly I have no idea! Thanks anyway!