Hey all,
I have a small problem i need to make the following Code execute once only on MouseDown but have no idea how to do it
if (Input.GetMouseButtonDown (0)) {
TileRay = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (TileRay, out TileRayHit))
;
TileSelected = TileRayHit.transform.name;
MouseFirstPressPosition = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
{
Debug.Log (TileSelected);
Debug.Log (MouseFirstPressPosition);
}
}
if (Input.GetMouseButtonUp (0)) {
MouseSecondPressPosition = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
MouseCurrentSwipe = new Vector2 (MouseSecondPressPosition.x - MouseFirstPressPosition.x, MouseSecondPressPosition.y - MouseFirstPressPosition.y);
MouseCurrentSwipe.Normalize ();
{
Debug.Log (MouseSecondPressPosition);
}
}
if (!(MouseSecondPressPosition == MouseFirstPressPosition)) {
if (Mathf.Abs (MouseCurrentSwipe.x) > Mathf.Abs (MouseCurrentSwipe.y)) {
if (MouseCurrentSwipe.x < 0) {
Debug.Log ("Swipe Left");
MouseMovementDirection = "Left";
} else {
Debug.Log ("Swipe Right");
MouseMovementDirection = "Right";
}
} else {
if (MouseCurrentSwipe.y < 0) {
Debug.Log ("Swipe Down");
MouseMovementDirection = "Down";
} else {
Debug.Log ("Swipe Up");
MouseMovementDirection = "Up";
}
}
}
The Code works and does exactly what i want but i keeps returning the TileSelected and MouseMovement Direction constantly. not good when you a making a tile game that relies on if statements to move tiles.
↧