c# - 我刚开始学习一些统一教程,但由于某种原因被卡住了
问题描述
我刚开始学习一些统一教程并被错误“没有给出与'My_Script.movePlayer(Vector3)的所需形式参数'direction'相对应的参数”所困扰,我不知道为什么?
public class My_Script : MonoBehaviour
{
public float speed = 10.0f;//movement speed
private Rigidbody rb;
public Vector3 movement;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// Keyboard Input
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Jump");
float z = Input.GetAxis("Vertical");
movement = new Vector3(x, y, z);
}
private void Fixedupdate()
{
movePlayer();
}
void movePlayer(Vector3 direction)
{
rb.velocity = direction * speed;
}
}
解决方案
你的函数movePlayer(Vector3 direction)
有一个vector3类型的参数,但是当你在中调用这个函数时FixedUpdate()
,你忘了给它这个参数。所以你应该写:
private void Fixedupdate()
{
movePlayer(movement);
}
这应该可以解决您的问题。
推荐阅读
- oracle - oracle中“打开文件失败”的Https rest请求错误
- python - 在 python 3.7 中获取请求错误,超出最大尝试次数
- javascript - 如何在 React 中返回一个可设置的常量
- java - 我在java中将csv读入数组,试图将数组的内容设置为JComboBox
- javascript - 带有验证的日期掩码
- image-processing - 由于少量误报,骰子得分极低。为什么骰子得分不考虑真底片?
- google-pay - Google Pay 是否会批准将优惠垂直用于数字认证卡?
- javascript - 单选按钮返回未定义
- android - Flutter:路由到不同的 .dart 文件失败。返回黑屏
- python - 如何将字符串转换为多级 JSON?