它确实会更改状态并播放动画,但它是立即执行的,在状态之间进行切换时不会延迟慢动作。
接地是> HumanoidIdle
从地面到步行的过渡。这部分工作正常,在“接地”和“行走”之间的转换缓慢且平滑。
Walk参数是布尔类型。
问题是从漫游到使用的过渡。 立即从“步行”更改为“使用”,没有延迟/慢动作。
这是我用来触发状态的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class SpaceshipCutscene : MonoBehaviour
{
public Transform player;
public Transform[] npcs;
public Transform console;
public Camera FPSCamera;
public Camera mainCamera;
public Animator[] anim;
public float rotationSpeed = 3f;
private bool moveNpc = false;
// Use this for initialization
void Start()
{
}
private void Update()
{
if (moveNpc)
{
// Soldier 2 rotating and looking at player
Vector3 dir = player.position - npcs[0].position;
dir.y = 0; // keep the direction strictly horizontal
Quaternion rot = Quaternion.LookRotation(dir);
// slerp to the desired rotation over time
npcs[0].rotation = Quaternion.Slerp(npcs[0].rotation, rot, rotationSpeed * Time.deltaTime);
float dist = Vector3.Distance(npcs[1].position, console.position);
if (dist < 4f)
{
anim[1].SetTrigger("Use");
}
Vector3 dirToComputer = console.transform.position - npcs[1].position;
dirToComputer.y = 0;
Quaternion rot1 = Quaternion.LookRotation(dirToComputer);
npcs[1].rotation = Quaternion.Slerp(npcs[1].rotation, rot1, rotationSpeed * Time.deltaTime);
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "SpaceshipCutscene")
{
FPSCamera.enabled = false;
mainCamera.enabled = true;
moveNpc = true;
anim[0].SetBool("Aiming", true);
anim[1].SetBool("Walk", true);
}
}
}
答案 0 :(得分:1)