void Update() { if (shoot == false) { shootTimeLeft -= Time.deltaTime; } if (shootTimeLeft <= 0) { shoot = true; shootTimeLeft = shootTime; } Screen.lockCursor = true; clicker.magUpdate(Input.acceleration, Input.compass.rawVector); if (clicker.clicked() || Input.GetMouseButtonDown(0)) { if (shoot == true && ammo > 0) { ammo -= 1; if (ammoLabel != null) { ammoLabel.text = "Ammo: " + ammo.ToString(); } Ray ray = new Ray(transform.position, transform.forward); Debug.DrawRay(transform.position, transform.forward * 100, Color.red); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { Debug.Log(hitInfo.collider.gameObject.name); Shootable hit = hitInfo.collider.GetComponent <Shootable> (); if (hit != null) { hit.Hit(transform.forward); } Instantiate(hitEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); } shoot = false; } } }
/// <summary> /// Explodes the rocket if it hits the room or an enemy. /// </summary> /// <param name="other"> The other collider </param> private void OnTriggerEnter(Collider other) { if (other.CompareTag("Enemy")) { explosionTarget = other.gameObject; other.GetComponent <Enemy>().Hit(damage * damageMultiplier, (behaviorFlags & RocketFlags.HapticFeedback) != 0); Explode(); } else if (other.CompareTag("Shootable")) { Shootable shootable = other.GetComponent <Shootable>(); if (shootable != null) { shootable.Hit(); } shipController.hand.controller.TriggerHapticPulse(2500); Explode(); } else if (other.CompareTag("Room")) { Explode(); } }