我认为即时通讯在控制动画过渡及其参数方面犯了一个错误。ima是一个完整的初学者,可以统一。 。 过渡是
怠速运行; isRunning = true
运行至空闲状态; isRunning = false
奔跑跳跃; isJumping = true
空转; isjumping = true
跳到空闲; isjumpinh = false
我尝试做几件事,但没有成功..如果这是一个初学者的问题,对不起,但我无法使其正常工作
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator anim;
private Rigidbody rb;
float runningSpeed = 30f;
float jumpForce = 20f;
bool isJumping = false;
bool isRunning = false;
// Start is called before the first frame update
void Start()
{
anim = this.gameObject.GetComponent<Animator>();
rb = this.gameObject.GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
move();
if (Input.GetKeyDown(KeyCode.Space))
{
jump();
}
animate();
}
void move()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(runningSpeed * Vector3.forward * Time.deltaTime);
isRunning = true;
}
else
{
isRunning = false;
}
}
void jump()
{
rb.AddForce(jumpForce * Vector3.up , ForceMode.Impulse);
isJumping = true;
}
void animate()
{
anim.SetBool("isRunning",isRunning);
anim.SetBool("isJumping", isJumping);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.name == "Ground" && isJumping)
isJumping = false;
}
}