2016-04-15 76 views
-1

我已經嘗試檢查文檔,它似乎對我來說是正確的,但當我嘗試構建此項目時仍然出現錯誤。我不知道如何處理input.getaxis(「垂直」)中的錯誤?

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); 
    } 
} 
+1

那麼是什麼錯誤? –

回答

0

你的錯誤是這兩行:

Input side = Input.GetAxis("Horizontal"); 
Input up = Input.GetAxis("Vertical"); 

Input.GetAxis回報float但你將其賦值給Input這是一個float和不甚至沒有存在。因此,請將Input sideInput up替換爲float sidefloat up

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); 


    } 
} 
相關問題