Unity Community


Results 1 to 2 of 2

  1. Posts
    48

    Turret Death Script

    I currently have a turret in game which fires small boxes at the player when the player is within a certain range of the turret. However I am stuck for what to do next script-wise. I need the bullet to kill the player on contact and load the level again. The script I have for my turret is as follows:
    Code:  
    1. private var target : Transform;
    2.  
    3.  
    4. if (otherCollider.CompareTag("Player"))
    5. {
    6. target = otherCollider.transform;
    7. Fire();
    8. }
    9. }
    10.  
    11. if (otherCollider.CompareTag("Player"))
    12. {
    13. target = null;
    14. StopCoroutine("Fire"); // aborts the currently running Fire() coroutine
    15. }
    16. }
    17.  
    18. function Fire()
    19. {
    20. while (target != null)
    21. {
    22. var nextFire = Time.time + 2;
    23. while (Time.time < nextFire)
    24. {
    25. transform.LookAt(target);
    26. yield WaitForEndOfFrame();
    27. }
    28.  
    29. // fire!
    30. var bullet = Instantiate(bulletPrefab, transform.position, transform.rotation);
    31. bullet.velocity = transform.forward * bulletSpeed;
    32. }
    33. }
    What would I need to add to this code or the box in order to make the level re-load from the beginning? I'm aware of the application.LoadLevel(1) code, but I'm not sure how I would go about triggering this code when the box or bullet hits the player. For reference I am using a default third person controller.

    Thanks in advance


  2. Location
    Brazil
    Posts
    228
    For me you need to add a new function in the player instead to add it too the turret. In this script in the player, you can check if your player collides with the bullet, subtract the health, kill the player. Also this way you can activate some boolean to ignore the player commands while the death animation is playing.
    My First Project, ArrowHead, a 2.5D Platform game: http://forum.unity3d.com/threads/130...-Platform-game

    My Second Project, RGBoom, a Platform Game too: http://forum.unity3d.com/threads/232...-platform-game

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •