Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- /*
- * --Bullet_Unit.js
- * @author: Paul Scharnofske
- * @version: 1.0.0
- *
- * This Script have to be bound to the bullet witch have to be shoot.
- * In this Script the bullet get it's movement and this Script also vanish
- * the first bullet (the sample bullet). (its not vanished but hidden
- * because of the position)
- */
- // Speed of the bullet
- var speed : float = 0.4f;
- // lifetime
- var lifetime : float = 10f;
- // Timepoint when the bullet spawns
- private var startTime : float;
- // Start function executet once when the bullet spawns
- function Start () {
- // startTime saves the actual time
- startTime = Time.time;
- }
- // alternative to Update() litte different
- function FixedUpdate () {
- // Let the bullet move forward
- transform.position += speed * transform.forward;
- // if lifetime is reached, destroy the bullet
- if(Time.time - startTime >= lifetime) { Destroy(this); }
- }
- // if the bullet hits something
- function OnCollisionEnter(collision : Collision) {
- // Destroys the bullet (later also test for the object it hits)
- Destroy(this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement