2014-07-11 47 views
0

我有一個GUI紋理,並附有以下腳本:使用GUI紋理移動播放器

using UnityEngine;

using System.Collections;

公共類前移:MonoBehaviour {

public float moveSpeed=3f; 
public GameObject player; 
void OnGUI() { 
     if (Input.GetMouseButton(0)) 
     player.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime); 

}

當我點擊GUI紋理它的工作原理,不僅,而且無論我在屏幕上點擊。

我該如何解決這個問題?

或者如果您有任何其他腳本用於移動使用GUI Texture的播放器,請隨時與我分享。

+0

您當前正在檢查鼠標左鍵是否關閉,移動....您還應該檢查鼠標位置是否在gui紋理內...您可以通過使用gui紋理Rect和使用。載(event.current.mousePosition);理解? – Savlon

回答

0

什麼OnMouseDown()?

OnMouseDown()當用戶按下鼠標按鍵,同時在GUIElement或對撞機被調用。