TeHArGiS10

Untitled

Jun 24th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #pragma strict
  2.  
  3. var Gun: GameObject;
  4. var Player: Transform;
  5. var Enemy: Transform;
  6. var EnemyHealth: GameObject;
  7. var EnemyHealthINT: int = 100;
  8. var hit: RaycastHit;
  9. var shootingDis: float = 15;
  10. var AmmoText: GameObject;
  11. var Ammo: int = 50;
  12.  
  13. function Start () {
  14. EnemyHealth.GetComponent(TextMesh).text = "100";
  15. AmmoText.GetComponent(UI.Text).text = "50";
  16. shootingDis = 15;
  17. }
  18.  
  19. function Update () {
  20. Enemy.transform.rotation = Quaternion.LookRotation(Enemy.position - Player.position);
  21. if (Physics.Raycast(transform.position, transform.forward, hit, shootingDis)) {
  22. if(hit.transform.tag == "Enemy") {
  23. if(Ammo >= 1) {
  24. if(Input.GetMouseButtonDown(0)) {
  25. EnemyHealthINT -= 10;
  26. EnemyHealth.GetComponent(TextMesh).text = EnemyHealthINT.ToString();
  27. }
  28. }
  29. }
  30. }
  31. if(Input.GetMouseButtonDown(0)) {
  32. AmmoText.GetComponent(UI.Text).text = Ammo.ToString();
  33. Ammo -= 1;
  34. }
  35. if(Input.GetKeyDown(KeyCode.R)) {
  36. Ammo = 50;
  37. AmmoText.GetComponent(UI.Text).text = Ammo.ToString();
  38. }
  39. if(Ammo <= 0) {
  40. Ammo = 0;
  41. }
  42. if (EnemyHealthINT == 0) {
  43. Destroy(Enemy.gameObject);
  44. }
  45. }
Add Comment
Please, Sign In to add comment