private void OnTriggerEnter(Collider other) { Debug.Log("hit..."); // Try and get the asteroid component of the hit collider. Asteroid asteroid = other.GetComponent <Asteroid>(); Opponent opponent = other.GetComponent <Opponent>(); // If it doesn't exist return. if (asteroid == null && opponent == null) { return; } // call the Hit function of the asteroid. if (asteroid != null) { asteroid.Hit(); Debug.Log("asteroid hit..."); } // or the hit function of the opponent if (opponent != null) { opponent.Hit(); Debug.Log("opponent hit..."); } // The laser has hit something. m_Hit = true; // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); }
private void OnTriggerEnter(Collider other) { // Try and get the asteroid component of the hit collider. Asteroid asteroid = other.GetComponent <Asteroid>(); // If it doesn't exist return. if (asteroid == null) { return; } // Otherwise call the Hit function of the asteroid. asteroid.Hit(); // The laser has hit something. m_Hit = true; // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.name.Contains("FlyerShark")) { Shark shark = other.gameObject.GetComponent<Shark>(); shark.Hit(); // The laser has hit something. m_Hit = true; dolphin.hitAudio.Play(); // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); } if (other.gameObject.name.Contains("FlyerAsteroid")) { Asteroid asteroid = other.gameObject.GetComponent<Asteroid>(); asteroid.Hit(); // The laser has hit something. m_Hit = true; dolphin.hitAudio.Play(); // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); } if (other.gameObject.name.Contains("FlyerOctopus")) { Pearl pearl = other.gameObject.GetComponent<Pearl>(); pearl.Hit(); dolphin.hitAudio.Play(); // The laser has hit something. m_Hit = true; // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); } if (other.gameObject.name.Contains("FlyerUrchin")) { Myst myst = other.gameObject.GetComponent<Myst>(); myst.Hit(); dolphin.hitAudio.Play(); // The laser has hit something. m_Hit = true; // Return the laser to the object pool. ObjectPool.ReturnGameObjectToPool(gameObject); } }