Subversion Repository Public Repository

Nextrek

Diff Revisions 133 vs 134 for /3DSpace/Assets/Custum/Scripts/GameManager.cs

Diff revisions: vs.
  @@ -8,9 +8,9 @@
8 8
9 9 public Transform explosionEffect;
10 10
11 - public static string HERO_NAME = "Player";
12 - public static string ENEMY_NAME = "Enemy";
13 - public static string ALLY_NAME = "Ally";
11 + public static string HERO_TAG = "Player";
12 + public static string ENEMY_TAG = "Enemy";
13 + public static string ALLY_TAG = "Ally";
14 14
15 15 void Awake()
16 16 {
  @@ -54,7 +54,7 @@
54 54
55 55 public static Transform GetHero()
56 56 {
57 - GameObject heroGameObject = GameObject.FindGameObjectWithTag(HERO_NAME);
57 + GameObject heroGameObject = GameObject.FindGameObjectWithTag(HERO_TAG);
58 58 if (heroGameObject != null) {
59 59 return heroGameObject.transform;
60 60 }
  @@ -63,7 +63,7 @@
63 63
64 64 public static GameObject GetClosestEnemy(Transform observer)
65 65 {
66 - GameObject[] enemies = GameObject.FindGameObjectsWithTag(ENEMY_NAME);
66 + GameObject[] enemies = GameObject.FindGameObjectsWithTag(ENEMY_TAG);
67 67
68 68 GameObject closest = null;
69 69 float bestScore = Mathf.Infinity;
  @@ -93,6 +93,38 @@
93 93 return closest;
94 94 }
95 95
96 + public static void HandleWeaponHit(RaycastHit _hit, float hitPower, Transform firedBy, Transform explosionEffect, Quaternion _rotation)
97 + {
98 + if(_hit.transform.tag==HERO_TAG && firedBy.tag!=HERO_TAG)
99 + {
100 + Life l = _hit.transform.GetComponent<Life>();
101 + if(l!=null)
102 + l.getHitted(hitPower);
103 + CommunicationCenter.Instance.ShowSmallCamera2(true);
104 + }
105 + else if(_hit.transform.tag==ENEMY_TAG)
106 + {
107 + EnemyShip es = _hit.transform.GetComponent<EnemyShip>();
108 + if(es!=null)
109 + es.getHitted(hitPower);
110 + }
111 + else if(_hit.transform.tag==ALLY_TAG)
112 + {
113 + AllyShip a = _hit.transform.GetComponent<AllyShip>();
114 + if(a !=null)
115 + a.getHitted(hitPower);
116 + }
117 + else if (_hit.transform.tag!=HERO_TAG && Random.Range(0,20) < 2)
118 + {
119 + MessageWindow.Instance.NewMessage ("An asteroid has been destroyed");
120 +
121 + // Instantiate the explosion effect at the point of impact
122 + Instantiate(explosionEffect, _hit.transform.position, _rotation);
123 + // Destroy the game object that we just hit
124 + Destroy(_hit.transform.gameObject);
125 + }
126 + }
127 +
96 128 void Start()
97 129 {
98 130