First of all, my English ability just a little.
I made character and character movement.
(Also made Animation, Animator. Four directions)
I made to move the keyboard,
Up - keyboard “W”
Down - keyboard “S”
Right - keyboard “D”
Left - keyboard “A”
made in this format(this is a PlayerControllers Script).
Format is created as a keyboard works well.
But, How to create a GUI button, I do not know what to add, what to PlayerControllers Script.
I found roughly, there is a movie that uses GetAxisRaw and Rigidbody2D… I do not know at all.
Here are attached to PlayerControllers Script.
using UnityEngine;
using System.Collections;
public class PlayerControllers: MonoBehaviour {
public Animator anim;
public float speed;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.D))
{
transform.Translate(Vector2.right * speed);
}
if (Input.GetKey (KeyCode.A))
{
transform.Translate(-Vector2.right * speed);
}
if (Input.GetKey (KeyCode.W))
{
transform.Translate(Vector2.up * speed);
}
if (Input.GetKey (KeyCode.S))
{
transform.Translate(-Vector2.up * speed);
}
if (Input.GetKey (KeyCode.A)) {
anim.SetBool ("Left", true);
anim.SetBool ("Right", false);
anim.SetBool ("Up", false);
anim.SetBool ("Down", false);
}
if (Input.GetKey (KeyCode.S)) {
anim.SetBool ("Down", true);
anim.SetBool ("Up", false);
anim.SetBool ("Left", false);
anim.SetBool ("Right", false);
}
if (Input.GetKey (KeyCode.D)) {
anim.SetBool ("Right", true);
anim.SetBool ("Left", false);
anim.SetBool ("Up", false);
anim.SetBool ("Down", false);
}
if (Input.GetKey (KeyCode.W)) {
anim.SetBool ("Up", true);
anim.SetBool ("Down", false);
anim.SetBool ("Left", false);
anim.SetBool ("Right", false);
}
if(Input.GetKey (KeyCode.A)){
anim.SetBool("Player_Left", true);
}
else{
anim.SetBool ("Player_Left", false);
}
if(Input.GetKey (KeyCode.S)){
anim.SetBool("Player_Down", true);
}
else{
anim.SetBool ("Player_Down", false);
}
if(Input.GetKey (KeyCode.D)){
anim.SetBool("Player_Right", true);
}
else{
anim.SetBool ("Player_Right", false);
}
if(Input.GetKey (KeyCode.W)){
anim.SetBool("Player_Up", true);
}
else{
anim.SetBool ("Player_Up", false);
}
}
}
I would want to ask. To create a GUI button of the four directions,
and I want to move character to four directions (Up, Down, Right, Left), but it doesn’t work.
I do not know what to do in PlayerControllers Script added.
Also attach a Game Scene.
Please help me.
Thank you.