Quantcast
Channel: Answers by "Luke Briggs"
Viewing all articles
Browse latest Browse all 20

Answer by Luke Briggs

$
0
0
I think this is what your looking for :) var onDieObjects:GameObject[]=new GameObject[5]; var health:float=10f; function reduceHealth(by:float){ health-=by; //hasn't always got to be 1 this way! if(health<=0){ Destroy(gameObject);//destroy the object this scripts stuck to. var numberOfObjects=onDieObjects.length; var rand:int=Random.Range(0,numberOfObjects-1);//choose a random object if(rand==0){//baby rock! make it 3 times by doing a lil loop. //because this uses the same position/rotation theyll end up ontop of each other. for(var i=0;i<3;i++){ Instantiate(onDieObjects[0],transform.position,transform.rotation); } }else{ Instantiate(onDieObjects[rand],transform.position,transform.rotation); } } } function OnCollisionEnter( hit:Collision ){ if(hit.gameObject.tag == "PlayerGun") { reduceHealth(1); //hits a 1. } } The above has been tested out and should do what your looking for. In the **inspector** you'll see an **on die objects** option with a drop down. Click that and then select the objects you'd like to generate, with the baby rock one in **first** :) Hope that helps!

Viewing all articles
Browse latest Browse all 20

Trending Articles