我正在创建一个简单的游戏,现在我将移动我的播放器。我想用移动设备上的四个触摸按钮移动我的播放器。我正在使用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;
}
}
答案 0 :(得分:0)
如果您希望文本显示在按钮上,则只需在引号中选择“向左”,“向下”,“向上”和“向右”。如果您想要带有图像的按钮,请将GUITexture类型更改为纹理(或Texture2D),如此处所述 - http://docs.unity3d.com/ScriptReference/GUI.Button.html