Lock rotation when clicking

Asked

Viewed 16 times

-1

I’m making a Puzzle but I’ve caught it in one part. It seems simple, but I can’t find a solution. Well, I’m using the mouse to click on an object so that it will rotate to a certain angle, but I wanted that by clicking on the same object one more time, the click would be blocked, so the person who is playing, continue rotating the other objects without being able to rotate what has already been clicked. I want you to click, stop, go to the next square clicking and so on, because after clicking all, the phase ends, YOUWIN appearance.

I’m using this script for rotation

private void Onmousedown() { if (!Gamecontrol.youwin) Transform. Rotate(0f,0f,90f); } }

HELP ME KK THANK YOU!!

1 answer

0

Your question wasn’t very clear, but if I understand correctly, you want to allow just one click per object, right?

My suggestion is to create a variable bool clicked in your object script, which will store whether it has already been clicked or not. And use it to decide what to do when you detect a click:

public class RotatingObject : MonoBehaviour
{
    private bool clicked = false;
      
    void OnMouseDown()
    {
        // Se ainda não foi clicado
        if (!clicked)
        {
            // Roda o código que gira o objeto
            // ...

            // Marca como clicado pra impedir de girar denovo
            clicked = true;
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.