Hello! i am making a racing game where you can change your car anywhere by pressing “C” and choosing a car. i have a code that should do that but i dont want you to have more than 1 car at a time. is there a way to destroy all other cars when you spawn a new one?
i have tried to do
Destroy (HoverCar);
or
Destroy (Truck);
but it doesnt work. please could somebody tell me what i did wrong?
code:
var HoverCar : Transform;
var Truck : Transform;
var script : Camera;
function OnGUI () {
if (Input.GetAxis("C")){
if (GUI.Button(Rect(10,70,100,30),"Hover Car")){
Destroy (HoverCar);
Destroy (Truck);
Instantiate (HoverCar, Vector3 (542.78, 1.3, 312.64), Quaternion.identity);
script = GetComponent(Camera); script.enabled = false;
}
if (GUI.Button(Rect(10,100,100,30),"Truck")){
Destroy (Truck);
Destroy (HoverCar);
Instantiate(Truck, Vector3 (542.78, 1.3, 312.64), Quaternion.identity);
script = GetComponent(Camera); script.enabled = false;
}
}
}