Answer the question
In order to leave comments, you need to log in
How to properly use conditions in C#?
I am writing a test case in Unity, here is a piece
public class MovePlayer : MonoBehaviour{
public Transform player;
void OnMouseDrag(){
Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mousePos.x = mousePos.x > 3f ? 3f : mousePos.x;
/*--------*/
if (mousePos.x>3f) mousePos.x=3f; else mousePos.x;
/*--------*/
player.position = new Vector2 (mousePos.x, player.position.y);
}
}
mousePos.x = mousePos.x > 3f ? 3f : mousePos.x;
if (mousePos.x>3f) mousePos.x=3f; else mousePos.x;
Answer the question
In order to leave comments, you need to log in
And why are there generally yes the same conditions? The second condition does not make sense after the first, where everything has already been checked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question