C# 如何在脚本中使用bool参数在两个动画之间开始转换?
我在Walk和Idle之间添加了一个转换,并添加了一个新的参数名称Idle type bool。在转换中,我将退出时间设置为false,然后在条件中添加Idle参数,将其设置为false 但在运行游戏时,即使Idle参数设置为false,转换仍在工作 我希望在我的脚本中,在某些特定条件下,转换将在漫游和空闲之间开始C# 如何在脚本中使用bool参数在两个动画之间开始转换?,c#,unity3d,C#,Unity3d,我在Walk和Idle之间添加了一个转换,并添加了一个新的参数名称Idle type bool。在转换中,我将退出时间设置为false,然后在条件中添加Idle参数,将其设置为false 但在运行游戏时,即使Idle参数设置为false,转换仍在工作 我希望在我的脚本中,在某些特定条件下,转换将在漫游和空闲之间开始 using System.Collections; using System.Collections.Generic; using UnityEngine; public cla
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimatorController : MonoBehaviour
{
public Animator[] animators;
public Transform target;
public float speed = 1f;
public float rotationSpeed;
public bool slowDown = false;
private bool endRot = false;
private Vector3 center;
// Use this for initialization
void Start()
{
center = target.GetComponent<Renderer>().bounds.center;
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", speed);
}
}
// Update is called once per frame
void Update()
{
float distanceFromTarget = Vector3.Distance(animators[2].transform.position, target.position);
for(int i = 0; i < animators.Length; i++)
{
animators[2].transform.position = Vector3.MoveTowards(animators[2].transform.position, center, 0);
}
if (slowDown)
{
if (distanceFromTarget < 10)
{
float speed = (distanceFromTarget / 10) / 1;
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", speed);
}
}
}
if (distanceFromTarget < 3.5f)
{
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", 0);
}
if (!endRot)
{
Quaternion goalRotation = Quaternion.Euler(0f, 180f, 0f);
float angleToGoal = Quaternion.Angle(
goalRotation,
animators[0].transform.localRotation);
float angleThisFrame = Mathf.Min(angleToGoal, rotationSpeed * Time.deltaTime);
// use axis of Vector3.down to keep angles positive for ease of use
animators[0].transform.Rotate(Vector3.up, angleThisFrame);
animators[1].transform.Rotate(Vector3.down, angleThisFrame);
// We end if we rotated the remaining amount.
endRot = (angleThisFrame == angleToGoal);
}
}
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类AnimatorController:MonoBehavior
{
公共动画师[]动画师;
公共转型目标;
公共浮子速度=1f;
公众浮标轮换速度;
公共布尔减速=假;
private bool endRot=假;
私人矢量3中心;
//用于初始化
void Start()
{
center=target.GetComponent().bounds.center;
对于(int i=0;i
我想让它停在这里:
if (distanceFromTarget < 3.5f)
{
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", 0);
}
if(距离目标<3.5f)
{
对于(int i=0;i
慢慢地在走路和闲着之间平稳地变换。
过渡在编辑器中运行良好,但我希望它仅在距离小于3.5时开始,现在在运行游戏时过渡开始得更快。您没有告诉动画制作者进行过渡并更改动画 首先,您希望将转换条件更改为True。否则,您将告诉动画师:我的对象不是空闲的,但是,请启动空闲动画(默认为false,这意味着它将始终处于空闲状态) 其次,你想告诉动画师使用你的bool对象的状态
if (distanceFromTarget < 3.5f)
{
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetBool("Idle", true);
}
if(距离目标<3.5f)
{
对于(int i=0;i
当对象实际移动时,您可能希望在其他地方重新启动移动动画。为此,您需要从空闲状态过渡到移动状态,并遵循相同的逻辑
如果您想做的是较慢的过渡,我不确定平滑过渡语句是否正确