В основном он ходит вправо, влево и прыгает.
Как сделать, чтобы он следовал этим инструкциям:
Когда пользователь нажимает кнопку направления, персонаж не останавливается. ходить до тех пор, пока пользователь не отпустит кнопку, а когда вы нажмете кнопку прыжка, игрок прыгнет.
Это скрипт, который я использую для перемещения с помощью клавиатуры!
Код: Выделить всё
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public float velocity;
public Transform player;
private Animator animator;
public bool isGrounded;
public float force;
public float jumpTime = 0.4f;
public float jumpDelay = 0.4f;
public bool jumped = false;
public Transform ground;
private Gerenciador gerenciador;
// Use this for initialization
void Start ()
{
gerenciador = FindObjectOfType (typeof(Gerenciador)) as Gerenciador;
animator = player.GetComponent ();
gerenciador.StartGame ();
}
// Update is called once per frame
void Update ()
{
Move ();
}
void Move ()
{
isGrounded = Physics2D.Linecast (this.transform.position, ground.position, 1 0) {
transform.Translate (Vector2.right * velocity * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
if (Input.GetAxisRaw ("Horizontal") < 0) {
transform.Translate (Vector2.right * velocity * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 180);
}
if (Input.GetButtonDown ("Vertical") && isGrounded && !jumped) {
// rigidbody2D.AddForce (transform.up * force);
GetComponent ().AddForce (transform.up * force);
jumpTime = jumpDelay;
animator.SetTrigger ("jump");
jumped = true;
}
jumpTime -= Time.deltaTime;
if (jumpTime
Подробнее здесь: [url]https://stackoverflow.com/questions/36834622/2d-basic-movement-unity[/url]
Мобильная версия