How can i limit the rotation of an object, when a key is pressed?
In my game I'm trying to make a secret tunnel behind a painting. I want the player to be able to press a key that will make the painting dangle, like if it was held up by only one screw. That is how the player finds the secret tunnel, but he should only be able to press a key if hes close to the painting. I'm a newbie when it comes to code so i was hoping someone could help me out. I know it has to do with Input.GetKeyDown but when i do that my object rotates 360 degrees and i just want it to rotate a max of 94 degrees. And as for the second part of my problem i know i need colliders, but i don't understand them. Please Help! Thanks!
All i could come up with:
function Update()
{
if (Input.GetKeyDown("e"))
{
transform.Rotate(0, 0, 94);
}
{
if (Input.GetKeyDown("r"))
{
transform.Rotate(0, 0, -94);
}
}
}
Rotate changes the rotation of the transform by the specified amount every single frame. It doesn't specify a maximum rotation value. So you're essentially telling it to rotate -94 degrees every single frame that the keys are pressed. You might want to start by rotating with Time.deltaTime to get a feel for how much rotation you actually need.