人物行走的时候播放行走动画并有声音
走一下之后,停止,声音还是存在
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class plyer_move_next : MonoBehaviour
{
private CharacterController Controller;
public float speed = 3f;
public float RotateSpeed = 0.3f;
public Animator anim;
public AudioSource Sounds;
public bool soundsPlay = true;
public bool soundsEnd;
// Start is called before the first frame update
void Start()
{
Controller = transform.GetComponent<CharacterController>();
anim = GetComponentInChildren<Animator>();
Sounds = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
Move();
}
private void Move()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
var moveDirection = transform.forward * (speed * moveZ * Time.deltaTime);
if (moveDirection != Vector3.zero)
{
anim.SetFloat("speed",1);
PlayerSounds();
}
else if (moveDirection ==Vector3.zero)
{
anim.SetFloat("speed",0);
}
Controller.Move(moveDirection);
transform.Rotate(Vector3.up,moveX * RotateSpeed); //针对坐标轴旋转
}
private void PlayerSounds()
{
if (soundsPlay == true && soundsEnd == true)
{
Sounds.Play();
soundsEnd = false;
}
if (soundsPlay == false && soundsEnd == true)
{
Sounds.Stop();
soundsEnd = false;
}
}
}
报错:Assertion failed on expression: 'errors == MDB_SUCCESS || errors == MDB_NOTFOUND'
我尝试过很多类似于改变soundsEnd的值但是结果还是不正确的
我想要达到的结果是静止的时候没有声音,行走的时候有声音