Hello,I’ve been unlucky in searching for a solution on the furums which I am not able to find. I need to figure out how to make it possible for a classic 3rd person character to be controlled by GUI butons (arrows) instead of the cassual WASD style
I’m New to Unity but I think I can help you.
You could try this approach:
public void OnGUI(){
if (GUI.Button (new Rect (65,10,48,48),"Left")){
object.transform.velocity=(new Vector 3(-10,0,0));
}
}
Of course you need to change the object, size and position of your button (and eventually the 1 and/or Skin of the button) and the magnitude of the Velocity.
May be this will help Someone…
if(Input.touchCount > 0)
if (Up_Arrow.HitTest(Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Character_Animation = Animations.Movement;
transform.Translate(MoveDirection * Speed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 180, 0), 1.0f);
}
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
Character_Animation = Animations.Idle;
}
}
else if (Down_Arrow.HitTest(Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Character_Animation = Animations.Movement;
transform.Translate(MoveDirection * Speed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, 0), 1.0f);
}
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
Character_Animation = Animations.Idle;
}
}
else if (Left_Arrow.HitTest(Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Character_Animation = Animations.Movement;
transform.Translate(MoveDirection * Speed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 90, 0), 1.0f);
}
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
Character_Animation = Animations.Idle;
}
}
else if (Right_Arrow.HitTest(Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Character_Animation = Animations.Movement;
transform.Translate(MoveDirection * Speed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 270, 0), 1.0f);
}
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
Character_Animation = Animations.Idle;
}
}
Ofcourse you have to declare the variables for guitexture and drag our guitexture for this variable.