I am making a gun shooting script, but I do not know how to disable shooting when the player is running. Can someone help me with that?
void Shoot()
{
MuzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, Range))
{
Debug.Log(hit.transform.name);
EnemyHealth enemy = hit.transform.GetComponent<EnemyHealth>();
if (enemy != null)
{
enemy.TakeDamage(Damage);
}
}
}
Here is the movement section of my character controller script:
void Movement()
{
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * WalkSpeed * Time.deltaTime);
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * WalkSpeed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.LeftShift))
{
WalkSpeed = RunSpeed;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
WalkSpeed = DefaultSpeed;
}
}