Синтаксис:
Используется csharp
void OnGUI()
{
if (direction == Direction.none)
{
//To make the button invisible, add the property GUIStyle.none
//if (GUI.Button(new Rect(Screen.width - Screen.width/3,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
if (GUI.Button(new Rect(Screen.width - Screen.width/3,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("right") ;
direction = Direction.right;
}
if (GUI.Button(new Rect(0,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("left") ;
direction = Direction.left;
}
if (GUI.Button(new Rect(Screen.width/3,0,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("up") ;
direction = Direction.up;
}
if (GUI.Button(new Rect(Screen.width/3,Screen.height - Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("down") ;
direction = Direction.down;
}
}
}
void Update()
{
if (direction == Direction.none)
{
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey("right"))
{
direction = Direction.right;
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey("left"))
{
direction = Direction.left;
}
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey("up") )
{
direction = Direction.up;
}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey("down"))
{
direction = Direction.down;
}
{
if (direction == Direction.none)
{
//To make the button invisible, add the property GUIStyle.none
//if (GUI.Button(new Rect(Screen.width - Screen.width/3,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
if (GUI.Button(new Rect(Screen.width - Screen.width/3,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("right") ;
direction = Direction.right;
}
if (GUI.Button(new Rect(0,0+Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("left") ;
direction = Direction.left;
}
if (GUI.Button(new Rect(Screen.width/3,0,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("up") ;
direction = Direction.up;
}
if (GUI.Button(new Rect(Screen.width/3,Screen.height - Screen.height/3,Screen.width/3,Screen.height/3),"",GUIStyle.none))
{
Input.GetKey("down") ;
direction = Direction.down;
}
}
}
void Update()
{
if (direction == Direction.none)
{
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey("right"))
{
direction = Direction.right;
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey("left"))
{
direction = Direction.left;
}
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey("up") )
{
direction = Direction.up;
}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey("down"))
{
direction = Direction.down;
}