Please forgive this newbie question, I seem to misunderstand prefabs thoroughly. I have a Universe class which dynamically instantiates many prefab Cars during start. That Car has a component C# script Car and I dragged a CarShape cube over the prefab as its body.
Now my simple goal is that the car prefab code should manage its own goals and movement and such (look for destinations, stop at red light, and whatever other details it wants). The instantiation is this
public GameObject car; // I dragged the prefab into this inspector box
...
Instantiate( car, new Vector3(x, y, z), Quaternion.identity );
And the Update routine in the prefab code itself is this
void Update() {
Vector3 velocity = new Vector3(2, 0, 0);
transform.Translate(velocity * Time.fixedDeltaTime);
}
Now, I might already be doing this wrong, because at this point, how would I use say MovePosition() instead of above? How would I refer to CarShape to change its color? And is the rigidbody that makes up my prefab the prefab itself? As you can see, I’m confused, so thanks for any answers.