Search Unity

--> need some HELP with a little script <--

Discussion in 'Scripting' started by Katzenklo, May 4, 2008.

  1. Katzenklo

    Katzenklo

    Joined:
    May 4, 2008
    Posts:
    53
    Hey guys!

    I'm very new to scripting :? and I wanna make a script for a grenade (a simple sphere), that rolls over the terrain and will only explode if it touches the player.

    looking forward for responses :)
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Try this:

    Code (csharp):
    1. var explosion : GameObject;
    2.  
    3. function OnCollisionEnter (collision : Collision)
    4. {
    5.      if (collision.collider.name == "Player")
    6.           BlowUp ();
    7. }
    8.  
    9. function BlowUp ()
    10. {
    11.      if (explosion)
    12.           Instantiate (explosion, transform.position, transform.rotation);
    13.      
    14.      Destroy (gameObject);
    15. }
     
  3. Katzenklo

    Katzenklo

    Joined:
    May 4, 2008
    Posts:
    53
    works great, thx a lot!!