2016-04-15 7 views
-1

Ich habe versucht, die Dokumentation zu überprüfen und es scheint mir richtig, aber immer noch bekomme ich einen Fehler, wenn ich versuche, dieses Projekt zu bauen.Ich weiß nicht, wie ich mit dem Fehler in input.getaxis ("Vertical") umgehen soll?

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

also was ist der Fehler? –

Antwort

0

Ihre Fehler sind auf diesen beiden Linien:

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

Input.GetAxis kehrt float aber Sie zuweisen, dass zu Input die nicht ein float ist und tut nicht noch existieren. Ersetzen Sie also Input side und Input up durch float side und float 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); 


    } 
} 
Verwandte Themen