I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help
This is a situation where if you actually knew Unityscript you would know what the solution is… Let’s go through your question by looking at Key words:
I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help
Alright, the first keyword is game object. So you need to have a gameobject in your scene, and call it a certian name.
Random:Duh… Random.Range
Drive Over It: Colliders. Rigidbodies. Yay.
Respawn: Instantiate the “Item box” gameobject.
A few Seconds: Time, Time, Time!
I hope this answers your question.
You could do this on OnTriggerEnter(), select a random object with Random.Range(minval, maxval) and make use of yields to wait for the respawn (could be the objects renderer switch on/off).
I don’t know how to do it either, but here’s a good starting script to go with.
var items : GameObject [];
function OnTriggerEnter()
{
collider.enabled = false;
var index : int = Random.Range(1,items.length);
var thePrefab : GameObject = items[index];
var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
}