| | | 1 | | using System; |
| | | 2 | | using System.Collections; |
| | | 3 | | using Unity.XR.CoreUtils; |
| | | 4 | | using UnityEngine; |
| | | 5 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 6 | | |
| | | 7 | | public class Round : MonoBehaviour |
| | | 8 | | { |
| | | 9 | | |
| | | 10 | | public GameObject self; |
| | | 11 | | |
| | | 12 | | public GameObject explosion; |
| | | 13 | | |
| | | 14 | | public Rigidbody Rigidbody; |
| | | 15 | | |
| | | 16 | | public int damage; |
| | | 17 | | |
| | | 18 | | |
| | | 19 | | void OnTriggerEnter(Collider other) |
| | 534 | 20 | | { |
| | 534 | 21 | | Target target = other.gameObject.GetComponent<Target>(); |
| | | 22 | | |
| | 534 | 23 | | if (target != null) |
| | 0 | 24 | | { |
| | 0 | 25 | | Debug.Log("Hit"); |
| | | 26 | | |
| | 0 | 27 | | target.Hit(damage); |
| | | 28 | | |
| | 0 | 29 | | Instantiate(explosion, self.transform.position, self.transform.rotation); |
| | | 30 | | |
| | 0 | 31 | | Destroy(gameObject); // Deletes the round |
| | 0 | 32 | | } |
| | | 33 | | else |
| | 534 | 34 | | { |
| | 534 | 35 | | StartCoroutine(Wait()); |
| | 534 | 36 | | } |
| | | 37 | | |
| | 534 | 38 | | XRTarget XRTarget = other.gameObject.GetComponent<XRTarget>(); |
| | | 39 | | // Only attempts to inflict damage if the other game object has |
| | | 40 | | // the 'EnemyAi' component |
| | 534 | 41 | | if (XRTarget != null) |
| | 49 | 42 | | { |
| | 49 | 43 | | Debug.Log("Hit"); |
| | | 44 | | |
| | 49 | 45 | | XRTarget.Hit(damage); |
| | | 46 | | |
| | 49 | 47 | | Destroy(gameObject); // Deletes the round |
| | | 48 | | |
| | 49 | 49 | | } |
| | | 50 | | |
| | | 51 | | else |
| | 485 | 52 | | { |
| | 485 | 53 | | StartCoroutine(Wait()); |
| | 485 | 54 | | } |
| | | 55 | | |
| | 534 | 56 | | EnemyAi EnemyHealth = other.gameObject.GetComponent<EnemyAi>(); |
| | | 57 | | // Only attempts to inflict damage if the other game object has |
| | | 58 | | // the 'EnemyAi' component |
| | 534 | 59 | | if (EnemyHealth != null) |
| | 0 | 60 | | { |
| | 0 | 61 | | Debug.Log("Hit"); |
| | | 62 | | |
| | 0 | 63 | | EnemyHealth.TakeDamage(damage); |
| | | 64 | | |
| | 0 | 65 | | Destroy(gameObject); // Deletes the round |
| | | 66 | | |
| | 0 | 67 | | } |
| | | 68 | | else |
| | 534 | 69 | | { |
| | 534 | 70 | | StartCoroutine(Wait()); |
| | | 71 | | |
| | 534 | 72 | | } |
| | 534 | 73 | | } |
| | | 74 | | |
| | | 75 | | IEnumerator Wait() // <- its a standalone method |
| | 1553 | 76 | | { |
| | 1553 | 77 | | Debug.Log("Hello"); |
| | | 78 | | //wait 3 seconds |
| | 1553 | 79 | | yield return new WaitForSeconds(5); |
| | 78 | 80 | | Debug.Log("Goodbye"); |
| | 78 | 81 | | Destroy(gameObject); // Deletes the round |
| | 78 | 82 | | } |
| | | 83 | | } |