- Home /
How do I nest or use if/and correctly?
My values don't change when I hold down MouseButton(1). What's wrong with my nesting?
function Update () {
if(Input.GetMouseButtonDown(1)) {;
if (Input.GetAxis("Mouse Y")<0) {;
height = (height + 0.05);
if (height > maxHeight) {;
height = maxHeight;
}
}
if (Input.GetAxis("Mouse Y")>0) {;
height = (height - 0.05);
if (height < minHeight) {;
height = minHeight;
}
}
}
}
How can I combine my commands to say if GetMouseButtonDown(1) AND GetAxis("Mouse Y")?
Answer by whydoidoit · Mar 12, 2014 at 08:59 AM
So you do not need the ; at the end of your if lines - it looks ugly and it's doing nothing.
The reason the values don't change is that you are using GetMouseButtonDown which returns true only in the frame when the button is first depressed. You need to use GetMouseButton which will return true for all frames in which the button is held down.
Perfect! That worked. Thank you. And thanks for the tip on semi-colons. I'm going to clean those out.
I converted your answer to a comment (add comments with the hidden "add new comment" button on the right!)
Also could you tick my answer? Cheers :D
Your answer
Follow this Question
Related Questions
Input.mousePosition changing to (0,0) after GetMouseButtonUp 1 Answer
How to make an object appear only when I click and not when I drag 2 Answers
Mouse Over, Mouse Down, and Instantiate. 1 Answer
Spawn An Object Every 2 Units On The Y-Axis 1 Answer
How to translate something only on X axis on Y axis,once per mouse click? 1 Answer