Advertisement
Transformator

Bullet_Unit

Dec 22nd, 2014
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2. /*
  3. * --Bullet_Unit.js
  4. * @author: Paul Scharnofske
  5. * @version: 1.0.0
  6. *
  7. * This Script have to be bound to the bullet witch have to be shoot.
  8. * In this Script the bullet get it's movement and this Script also vanish
  9. * the first bullet (the sample bullet). (its not vanished but hidden
  10. * because of the position)
  11. */
  12.  
  13. // Speed of the bullet
  14. var speed : float = 0.4f;
  15. // lifetime
  16. var lifetime : float = 10f;
  17. // Timepoint when the bullet spawns
  18. private var startTime : float;
  19.  
  20. // Start function executet once when the bullet spawns
  21. function Start () {
  22.     // startTime saves the actual time
  23.     startTime = Time.time;
  24. }
  25.  
  26. // alternative to Update() litte different
  27. function FixedUpdate () {
  28.     // Let the bullet move forward
  29.     transform.position += speed * transform.forward;
  30.    
  31.     // if lifetime is reached, destroy the bullet
  32.     if(Time.time - startTime >= lifetime) { Destroy(this); }
  33. }
  34.  
  35. // if the bullet hits something
  36. function OnCollisionEnter(collision : Collision) {
  37.     // Destroys the bullet (later also test for the object it hits)
  38.     Destroy(this);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement