Aquí os voy a enseñar como pegar un pequeño Sprin.
lo primero que vamos hacer sera ir al sprinte del policía que es nuestro personaje y comenzaremos a programar
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Personajescript : MonoBehaviour { public float speed; private Rigidbody2D myRigibody; private Vector3 mover; private Animator animator; Vector2 mov; public GameObject correr_polvo; void Start() { animator = GetComponent<Animator>(); myRigibody = GetComponent<Rigidbody2D>(); } void Update() { mover = Vector3.zero; mover.x = Input.GetAxisRaw("Horizontal"); mover.y = Input.GetAxisRaw("Vertical"); UpdateAnimationAdnMove(); HandleMovement(); //// lo que tenemos que adjuntar a nuestro script } void UpdateAnimationAdnMove() { if (mover != Vector3.zero) { moveCharacter(); animator.SetFloat("MovX", mover.x); animator.SetFloat("MovY", mover.y); animator.SetBool("moving", true); } else { animator.SetBool("moving", false); } } void moveCharacter() { myRigibody.MovePosition(transform.position + mover * speed * Time.deltaTime); } private void HandleMovement() /// adjuntamos este cacho en el Script { if (Input.GetKeyDown(KeyCode.T)) { float dashDistance = 3f; transform.position += mover * dashDistance; /// hasta aquí adjuntamos } if (Input.GetKeyDown(KeyCode.T)) { Instantiate(correr_polvo, transform.position, Quaternion.identity); } } }
Y ya lo tendriamos.