2014-10-29 2 views
-3

Я создаю простую игру, и теперь я собираюсь переместить своего игрока. Я хочу переместить плеер с помощью четырех сенсорных кнопок для мобильных устройств. Я пользуюсь кнопками GuiTexture и использую следующий код. Тем не менее, я получаю эту ошибку:Невозможно переместить плеер с помощью GUI.Button

The best overloaded method match for UnityEngine.GUI.Button(UnityEngine.Rect, string) has some invalid arguments"

Как это исправить?

Код

public class Player : MonoBehaviour { 
    public float movement; 
    public Vector3 input; 
    private float maxSpeed=15f; 
    private Vector3 spawn; 
    public GameObject deathparticales; 
    public GUITexture Left; 
    public GUITexture Right; 
    public GUITexture Up; 
    public GUITexture Down; 
    private bool moveRight, moveLeft, moveUp, moveDown; 

    // Use this for initialization  
    void Start() { 
     spawn = transform.position; 
    } 

    // Update is called once per frame 
    void Update() { 
     if (GUI.Button(Rect (50,50,50,50), Left)) 
     { 
      Vector3 position = this.transform.position; 
      position.x--; 
      this.transform.position = position; 
     } 

     if (GUI.Button(Rect (100,50,50,50), Right)) 
     { 
      Vector3 position = this.transform.position; 
      position.x++; 
      this.transform.position = position; 
     } 

     if (GUI.Button(Rect (75,100,50,50), Up)) 
      { 
      Vector3 position = this.transform.position; 
      position.y++; 
      this.transform.position = position; 
     } 

     if (GUI.Button(Rect (25,100,50,50), Down)) 
     { 
      Vector3 position = this.transform.position; 
      position.y--; 
      this.transform.position = position; 
     } 

     if (transform.position.y < -1) { 
      Die(); 
     } 
    } 

    void OnCollisionEnter(Collision death) 
    { 
     if(death.transform.tag == "Enemycollision") 
     { 
      Die(); 

     } 
    } 

    void OnTriggerEnter(Collider target) 
    { 
     if (target.transform.tag == "Target") { 
     Gamemanager.completelevel(); 
     } 
    } 

    void Die() 
    { 
     Instantiate(deathparticales,transform.position,Quaternion.Euler(270,0,0)); 
     transform.position=spawn; 
    } 
} 
+0

Влево, вправо, вверх, вниз не строки, они объявлены как GUITexture – LearnCocos2D

+0

, как я могу это решить? пожалуйста, исправьте мой код? – user3866627

ответ

0

Если вы хотите текст, который будет отображаться на кнопках, то просто взять «влево», «Вниз», «Вверх» и «Right» в кавычках. Если вы хотите использовать кнопки с изображениями, то измените тип GUITexture на Texture (или Texture2D), как сказано здесь: http://docs.unity3d.com/ScriptReference/GUI.Button.html

Смежные вопросы