将您的 gui 纹理传递给播放器脚本并将其命名为“YourGuiTexture”。
有各种逻辑来检测 GuiTexture 最简化的命中如下:
在键盘上:
public GUITexture YourGuiTexture;
void Update() {
if (YourGuiTexture.HitTest(Input.mousePosition) //check if your mouse is on your gui texture
{
float move = Input.GetAxis ("Horizontal");
if (move < 0)
{
move = move;
}
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
}
}
在触摸移动设备上:
public GUITexture YourGuiTexture;
// Update is called once per frame
void Update ()
{
if (YourGuiTexture.HitTest(Input.GetTouch(0).position))
{
if(Input.GetTouch(0).phase==TouchPhase.Began)
{
float move = Input.GetAxis ("Horizontal");
if (move < 0)
{
move = move;
}
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
}
}
}