Search Unity

Health > Destory help

Discussion in 'Scripting' started by Luke3671, Mar 13, 2017.

  1. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    56
    Hello,
    I'm new learning Java, Basically with little help with using "Scripting API" part of unity & YouTube, I have got this so far;
    (Health of object script below)
    Code (JavaScript):
    1. // This section is health for object.
    2. var health :int = 8;
    3.  
    4. function Damage(damage:int){
    5.     health -= damage;
    6.     if(health <= 0)Destroy(gameObject);
    7. }
    8.  
    9.     // This section is effect when object is destoryed.
    10.     var explosion: GameObject;
    11.     //var clip : AudioClip;
    12.     function OnCollisionEnter(){
    13.         var expl = Instantiate(explosion, transform.position, Quaternion.identity);
    14.         Destroy(gameObject);
    15.         Destroy(expl, 5); // delete the object after 5 seconds.
    16.     }
    17.  
    18.     // Not working on Audio atm
    19.     // reload : AudioClip;
    20.  
    21.   //function Start() {
    22.     //    AudioSource.PlayClipAtPoint(clip, new Vector3 (5, 1, 2));
    23.     //}
    I also have "Bullet" which basically when "player hits item, Item loses health" (Depending what i've put health to) but what i need help with is;
    Particle system works fine does that it should do (But i want to use a prefab i've made instead of Particles this is where it stops working. When player hits object once it auto destroys and replaces it with the prefab. Is there a way to make it same as what the Particle system does just using objects instead?

    Thank you for your time & help
    Luke
     
  2. SgtZdog

    SgtZdog

    Joined:
    Aug 27, 2016
    Posts:
    33
    If I understand your question right, Instantiate will work with any prefab, not just your particles.