Я пытаюсь сделать так, чтобы персонаж быстро сделал небольшой рывок в направлении, в котором он движется после двойного нажатия кнопки.У меня есть слой переопределения в моем Animator, и я смешал дерево для всех направлений тире.Но я не могу заставить это работать вообще.Я потратил около 4 часов, пытаясь решить эту проблему самостоятельно, но я сдаюсь и могу использовать некоторую помощь или направление.
Примечание: я все еще довольно новичок в C #, но у меня огромный опыт в LUAтак что извините, если здесь есть очевидный недосмотр, я все еще учусь.
Код ниже:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DarkHaven
{
public class InputManager : MonoBehaviour
{
private float doublePressTime = 0.25f; // Amount of time between presses to trigger
private float lastPressTime = -10f; // Resets value
private float horizontal;
private float vertical;
Animator anim;
// Start is called before the first frame update
void Start()
{
anim = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
vertical = Input.GetAxis("Vertical");
horizontal = Input.GetAxis("Horizontal");
if (Input.GetButtonDown("Fire1")) // B Button is pressed
{
float timeDelta = Time.time - lastPressTime;
if(timeDelta < doublePressTime)
{
anim.SetFloat("Vertical", vertical);
anim.SetFloat("Horizontal", horizontal);
lastPressTime = 0;
anim.CrossFade("Dash",0.2f);
Debug.Log("Cancel Sprint and perform Dash");
}
else
{
lastPressTime = Time.time;
// anim.SetBool("IsSprinting", true);
}
}
if (Input.GetButtonUp("Fire1"))
{
//anim.SetBool("IsSprinting", false);
}
}
}
}