How to move a character by pressing a button?
I am new in Unity. Right now I am in deep trouble. I have a character in unity. I can move it through keyboard. Now I want to move that character(like: run,walk,jump) by using buttons. How can I move开发者_运维技巧 that character by using buttons? Please help me.....
If your game is still a web or desktop game as it probably was when you were using the keyboard, you could create a GUI button and also control it through the Input manager settings,GetBbutton functions and queued animations. So basically when a button is down/pressed the 'walk animation' would play. When the button is released he stops, or the idle animation is played. If its a IOS game and you're talking about touching or tapping an on screen button its the same process but a different way to achieve it!
Try this
var ball : Transform;
function Update()
{
if (Input.GetKey("up"))
{
ball.Translate(Vector3.up * Time.deltaTime, Space.World);
}
if (Input.GetKey("down"))
{
ball.Translate(Vector3.down * Time.deltaTime, Space.World);
}
if (Input.GetKey("right"))
{
ball.Translate(Vector3.right* Time.deltaTime, Space.World);
}
if (Input.GetKey("left"))
{
ball.Translate(Vector3.left* Time.deltaTime, Space.World);
}
}
精彩评论