public void Fire() { if (Time.time > nextFire) { // Start our ShotEffect coroutine to turn our laser line on and off StartCoroutine(ShotEffect()); // Update the time when our player can fire next nextFire = Time.time + fireRate; Vector3 rayOrigin = new Vector3(0.5f, 0.5f, 0f); // center of the screen GameObject hitObject = null; LoadingDoorScript hitDoor = null; WeaponChargeObject hitChargeObject = null; // actual Ray Ray ray = PlayerCamera.ViewportPointToRay(rayOrigin); // debug Ray Debug.DrawRay(ray.origin, ray.direction * weaponRange, Color.white); GameObject VFXGo = Instantiate(FireEffect, gunEndGO.transform.position, PlayerCamera.transform.rotation); if (Physics.Raycast(ray, out hit, weaponRange)) { if (hit.collider != null) { hitObject = hit.collider.gameObject; //Debug.Log(hit.collider.gameObject); if (hitObject.GetComponent <Enemy>()) { hitObject.GetComponent <Enemy>().damageEvent.Invoke(DamageAmount); } if (hitObject.GetComponentInChildren <ID_LoadDoor>()) { hitDoor = hitObject.GetComponentInParent <LoadingDoorScript>(); hitDoor.CheckAmmoType(MyAmmoType); //TODO: If it's the wrong ammo type, bounce the shot back to player } if (hitObject.GetComponent <WeaponChargeObject>()) { float chargeAmount = DamageAmount / 4; hitChargeObject = hitObject.GetComponent <WeaponChargeObject>(); hitChargeObject.ModCharge(chargeAmount, MyAmmoType); } } } } }
// Start is called before the first frame update void Start() { GetDoorScript = GetComponentInParent <LoadingDoorScript>(); }