Unity3d 我不知道';我不知道如何处理input.getaxis(“垂直”)中的错误?
我已经尝试过检查文档,它对我来说似乎是正确的,但当我尝试构建这个项目时,仍然会遇到一个错误Unity3d 我不知道';我不知道如何处理input.getaxis(“垂直”)中的错误?,unity3d,c#-3.0,unity5,Unity3d,C# 3.0,Unity5,我已经尝试过检查文档,它对我来说似乎是正确的,但当我尝试构建这个项目时,仍然会遇到一个错误 using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { private Rigidbody rb; void Start () { rb = GetComponent<Rigidbody> (); } void
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
void Start () {
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate () {
Input side = Input.GetAxis("Horizontal");
Input up = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (side, 0.0f, up);
rb.AddForce (movement);
}
}
使用UnityEngine;
使用系统集合;
公共类玩家控制器:单行为{
私人刚体;
无效开始(){
rb=GetComponent();
}
无效固定更新(){
输入侧=Input.GetAxis(“水平”);
Input up=Input.GetAxis(“垂直”);
矢量3移动=新矢量3(侧面,0.0f,向上);
rb.AddForce(移动);
}
}
您的错误在以下两行:
Input side = Input.GetAxis("Horizontal");
Input up = Input.GetAxis("Vertical");
Input.GetAxis
返回float
,但您正在将其分配给Input
,它是而不是afloat
,甚至不存在。因此,将输入端
和向上输入
替换为浮动端
和向上浮动
public class PlayerController : MonoBehaviour {
// Use this for initialization
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float side = Input.GetAxis("Horizontal");
float up = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(side, 0.0f, up);
rb.AddForce(movement);
}
}
公共类PlayerController:MonoBehavior{
//用于初始化
私人刚体;
void Start()
{
rb=GetComponent();
}
//每帧调用一次更新
void FixedUpdate()
{
float side=Input.GetAxis(“水平”);
向上浮动=Input.GetAxis(“垂直”);
矢量3移动=新矢量3(侧面,0.0f,向上);
rb.AddForce(运动);
}
}
那么错误是什么?