我正在创建一个简单的游戏,现在我要移动我的玩家。我想移动我的播放器使用四个触摸按钮的移动。我正在使用GuiTexture
按钮并使用下面的代码。然而,我得到了这个错误:
UnityEngine.GUI.Button(UnityEngine.Rect, string)
的最佳重载方法匹配有一些无效参数"
如何修复?
代码
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;
}
}
如果您希望文本显示在按钮上,那么只需在引号中加上"左"、"下"、"上"one_answers"右"即可。如果你想要带图像的按钮,那么将GUITTexture类型更改为Texture(或Texture2D),如下所述-http://docs.unity3d.com/ScriptReference/GUI.Button.html