Unity3d 未将参数值从脚本发送到混合树(Unity 2020)
(参数值没有从脚本发送到混合树,导致没有跟随动画移动。)我在具有1d类型混合树的混合树中设置了动画。我将其设置为自定义阈值,以空闲动画作为基本状态,然后混合树有三个运动:左扫射、右扫射和向前行走。当我向前移动时,玩家不会执行树中告诉的动画,我几乎可以肯定这就是脚本 我也在使用Unity 1212.1.2f1,对于我的脚本,如果有必要的话,我一直在使用Microsoft Visual StudioUnity3d 未将参数值从脚本发送到混合树(Unity 2020),unity3d,Unity3d,(参数值没有从脚本发送到混合树,导致没有跟随动画移动。)我在具有1d类型混合树的混合树中设置了动画。我将其设置为自定义阈值,以空闲动画作为基本状态,然后混合树有三个运动:左扫射、右扫射和向前行走。当我向前移动时,玩家不会执行树中告诉的动画,我几乎可以肯定这就是脚本 我也在使用Unity 1212.1.2f1,对于我的脚本,如果有必要的话,我一直在使用Microsoft Visual Studio using System.Collections; using System.Collections
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public float rotationSpeed = 75.0f;
public Animator anim;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
if ((Input.GetButtonDown("Jump")) && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
{
anim.SetFloat("Vertical", Input.GetAxis("Vertical"));
anim.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
}
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类玩家运动:单一行为
{
公共字符控制器;
公共浮子速度=12f;
公共浮子重力=-9.81f;
公共浮子跳线高度=3f;
公共浮子旋转速度=75.0f;
公共动画;
公开审查;
公共浮地距离=0.4f;
公共层掩码地面掩码;
矢量3速度;
布尔被禁足;
//在第一帧更新之前调用Start
void Start()
{
anim=GetComponent();
}
//每帧调用一次更新
无效更新()
{
isground=physical.CheckSphere(groundCheck.position、groundDistance、groundMask);
浮点平移=输入。GetAxis(“垂直”)*速度;
浮动旋转=输入。GetAxis(“水平”)*旋转速度;
translation*=Time.deltaTime;
旋转*=时间增量时间;
如果(isGrounded&&velocity.y<0)
{
速度y=-2f;
}
float x=Input.GetAxis(“水平”);
float z=Input.GetAxis(“垂直”);
if((Input.GetButtonDown(“跳转”)&&isground)
{
速度y=数学Sqrt(跳跃高度*-2f*重力);
}
Vector3 move=transform.right*x+transform.forward*z;
控制器。移动(移动*速度*时间。延迟时间);
速度.y+=重力*时间增量;
控制器。移动(速度*时间。增量时间);
{
anim.SetFloat(“垂直”,Input.GetAxis(“垂直”);
anim.SetFloat(“水平”,Input.GetAxis(“水平”);
}
}
}
首先,我认为您可以尝试创建一个新的变量:
private Rigidbody2D rg;
然后将其添加到Start()中
确保在Animator参数中有2个垂直和水平这是一个好主意,但仍然无法解决问题。我没有在我的播放器上使用刚体,因为脚本决定了我的值,所以没有必要使用它,而添加刚体实际上会使情况变得更糟。添加刚体后,它会在前进时删除当前动画。还有其他想法吗?也许你们可以试试这个,因为我们也使用了更新方法:anim.SetFloat(“垂直”,x);动画设置浮动(“水平”,z);
rg = Player.GetComponent<Rigidbody2D>();
anim.SetFloat("Vertical", rg.velocity.x);
anim.SetFloat("Horizontal", rgvelocity.x);