エラー本文
Parameter 'MoveSpeed' does not exist.
UnityEngine.Animator:SetFloat (string,single)
PlayerController:Update () (at Assets/iigeemu/script/PlayerController.cs:51)
日本語訳すると、「「パラメーター " "MoveSpeed"は は存在しません。」ということだと思いますが、似たようなエラーでよくあるスクリプトのタイプミスなどは確認しました。
移動スピードをanimatorに反映させるためのスクリプトです。何卒よろしくお願いします。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;エラー本文
Parameter 'MoveSpeed' does not exist.
UnityEngine.Animator:SetFloat (string,single)
PlayerController:Update () (at Assets/iigeemu/script/PlayerController.cs:51)
public class PlayerController : MonoBehaviour
{
[SerializeField] private Animator animator;
[SerializeField] private float moveSpeed = 10;
[SerializeField] private float jumpPower = 3;
private CharacterController _characterController;ソースコード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] private Animator animator;
[SerializeField] private float moveSpeed = 10;
[SerializeField] private float jumpPower = 3;
private CharacterController _characterController;
private Transform _transform;
private Vector3 _moveVelocity;
private Transform _transform;
private Vector3 _moveVelocity;
// Start is called before the first frame update
void Start()
{
_characterController = GetComponent<CharacterController>();
_transform = transform;
}
// Update is called once per frame
void Update() {
{
Debug.Log(_characterController.isGrounded ? "地上にいます" : "空中です");
_moveVelocity.x = Input.GetAxis("Horizontal") * moveSpeed;
_moveVelocity.z = Input.GetAxis("Vertical") * moveSpeed;
_transform.LookAt(_transform.position + new Vector3(_moveVelocity.x, 0, _moveVelocity.z));
if (_characterController.isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
Debug.Log("ジャンプ!");
_moveVelocity.y = jumpPower;
}
}
else
{
_moveVelocity.y += Physics.gravity.y * Time.deltaTime;
}
_characterController.Move(_moveVelocity * Time.deltaTime);
}
animator.SetFloat("MoveSpeed", new Vector3(_moveVelocity.x, 0,_moveVelocity.z).magnitude);
}
}
}