//public bool reloaded = true; public override void Shoot() { if (reloaded == true) { ShotAudio.Play(); LazerBeam.enabled = true; Ray ray = PlayerCam.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2) /*new Vector3(0.5f, 0, 0.5f)*/); //ray.origin = PlayerCam.transform.position; LazerBeam.SetPosition(0, Vector3.zero); Invoke(nameof(LazerOff), 0.2f); Invoke(nameof(Reload), 2.5f); reloaded = false; if (Physics.Raycast(ray, out RaycastHit hit)) { LazerBeam.SetPosition(1, transform.InverseTransformPoint(hit.point)); PlayerScript.DrawShotLine(1, hit.point); if (hit.collider.gameObject.GetComponent <PlayerController>() != null) { hit.collider.gameObject.GetComponent <PlayerController>().TakeDamage(damage); //PlayerScript.TakeDamage(); } Debug.Log("We hit" + hit.collider.name); } else { LazerBeam.SetPosition(1, new Vector3(580, -4547, 40)); PlayerScript.DrawShotLine(1, new Vector3(580, -4547, 40)); } } }
public override void Shoot() { if (reloaded == true && Time.time >= nextfire) { if (WorkingParticleSystem == false) { flash.Play(); WorkingParticleSystem = true; PlayerScript.ShowMachineGunShooting(true); } ShotAudio.Play(); nextfire = Time.time + 1f / fireRate; RaycastHit hit; if (Physics.Raycast(PlayerCam.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)), out hit)) { if (hit.collider.gameObject.GetComponent <PlayerController>() != null) { hit.collider.gameObject.GetComponent <PlayerController>().TakeDamage(damage); } Debug.Log("We hit" + hit.collider.name); } } }