2013-07-03 6 views

답변

4

기본적으로 할 수 없습니다. 이미 알고 있듯이 더 나은 단어를 사용하면 GUI.Button은 버튼을 눌렀는지 나타내는 bool을 반환합니다. 실제로 모든 프레임을 버튼을 만드는 다시 때문에

당신이 GUI.Button를 호출 할 때, 당신은에 의해 그것에게 Rect 경계를 통과하는 (당신의 GUI.Button 코드는 다음과 같은 Update, FixedUpdate는, OnGUI ... 콜백 내부) 자아, 실제 좌표를 검색하기 위해 객체를 쿼리 할 필요가 실제로 없습니다. 간단히 어딘가에 저장하십시오.

Rect buttonBounds = new Rect (50,60,100,20); 

bool buttonPressed = GUI.Button (buttonBounds, "get postion"); 

if (buttonPressed) 
{ 
    //you know the bounds, because buttonBounds button has been pressed 
} 
0

이 시도 :

var positionGui : Vector2; 
positionGui = Vector2 (guiElement.transform.position.x * Screen.width, guiElement.transform.position.y * Screen.height); 
0

는이

public static Rect screenRect 
    (float tx, 
    float ty, 
    float tw, 
    float th) 
{ 
    float x1 = tx * Screen.width; 
    float y1 = ty * Screen.height;  
    float sw = tw * Screen.width; 
    float sh = th * Screen.height; 
    return new Rect(x1,y1,sw,sh); 
} 
public void OnGUI() 
{ 


    if (GUI.Button(screenRect(0.4f, 0.6f, 0.2f, 0.1f), "TRY AGAIN")) 

{ 
    Application.LoadLevel(0); 

} 

print ("button position + framesize"+screenRect(0.4f, 0.6f, 0.2f, 0.1f)); 

} 
처럼 뭔가를 할 수