c# – Unity OnMouseDrag issue
I’m having trouble activating a sound when I rotate a statue. I have to hold down the control key and click on the object to make it rotate. The sound activates correctly and most of the time it turns off, but sometimes it keeps playing and never turns off.
KeyCode pickUpKey = KeyCode.LeftControl;
float rotationSpeed = 0.5f;
AudioSource idolMoving;
void Awake()
{
idolMoving = GetComponent();
}
void OnMouseDrag()
{
float yAxisRotation = Input.GetAxis("Mouse X") * rotationSpeed;
transform.Rotate(Vector3.up, yAxisRotation, Space.Self);
if (Input.GetAxis("Mouse X") != 0 && Input.GetKey(pickUpKey))
{
idolMoving.enabled = true;
}
else
{
idolMoving.enabled = false;
}
}
Has this happened to anyone else or knows how to fix it? Thanks in advance.
Read more here: Source link
