[英]Vector2 does not contain a definition (Unity Roll A Ball Tutorial)
所以我在做 Unity Roll-A-Ball 教程,我正在移动播放器的第 8 步。 当我键入所有代码时,它会引发错误'Vector2 does not contain a definition for 'Y' and no accessible extension method 'Y' accepting a first argument type of 'Vector2' could be found. (are you missing a using directive or an assembly reference?)
'Vector2 does not contain a definition for 'Y' and no accessible extension method 'Y' accepting a first argument type of 'Vector2' could be found. (are you missing a using directive or an assembly reference?)
任何帮助,将不胜感激
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
private float movementX;
private float movementY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnMove(InputValue movementValue)
{
//Function Body
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.X;
movementY = movementVector.Y;
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement);
}
}
Vector2、Vector3中的字段名是小写的x、y、z。
您可以在 IDE 中单击(设置回车位置)代表类型(如“Vector2”)的字符串,然后按 F12 以查看里面的内容或直接写:
movementVector.
并等待IDE的建议。 如果它们没有出现,请按 Ctrl + 空格键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.