2011-10-27 7 views
1

개체와 GUI 텍스쳐 버튼 2 개가 있습니다. 왼쪽 버튼을 누르면 객체를 왼쪽으로 회전시키고 다른 객체를 누르면 오른쪽으로 객체를 회전시키고 싶습니다.버튼을 클릭하여 게임 개체를 회전하십시오.

아이디어가 있으십니까?

개체를 끌 때 작동하는 스크립트가 있습니다. 나는 중요한 부분을 게시 할 예정입니다 :

function Start() 
{ 
    var angles = transform.eulerAngles; 
    x = angles.y;  

    // Make the rigid body not change rotation 
    if (rigidbody) 
    rigidbody.freezeRotation = true;  
} 

function LateUpdate() 
{ 
    if (isMouseOverGuiTexture()) return; 

    if (target && Input.GetMouseButton(0)) 
    { 
     //0.1 represents the sensitivity of the mouse 
     x += Input.GetAxis("Mouse X") * xSpeed *0.1; //x rotation 
     //y -= Input.GetAxis("Mouse Y") * ySpeed *0.1; //y rotation 
     //y = ClampAngle(y, yMinLimit, yMaxLimit);     
     var rotation = Quaternion.Euler(y, x, 0); 
     var position = rotation * Vector3(0.900528, 8.829305, -distance+0.49548)+ target.position; 

     transform.rotation = rotation; 
     transform.position = position; 
    } 
} 
+0

어떤 API입니까? 자바 스크립트 같은데? – trojanfoe

+0

유니티 3d와 코드는 자바 스크립트입니다. –

+0

나는 내 질문을 편집하고 답변을 추가했습니다. 미안해, 내가 잘못 했어. –

답변

0

(질문 코멘트에 대답 Question with no answers, but issue solved in the comments (or extended in chat)를 참조하십시오.)

영업 쓴 :

var imageLeft: Texture2D; // drag the left button image here 
var imageRight: Texture2D; // right button image 
var speed: float = 60; // rotate speed in degrees per second 
private var rotLeft = false; // object rotates left if true 
private var rotRight = false; // object rotates right if true; 

function OnGUI() 
{ 
    rotLeft = GUI.RepeatButton(Rect(10,10,200,200), imageLeft); 
    rotRight = GUI.RepeatButton(Rect(230,10,200,200), imageRight); 
} 

function Update() 
{  
    if (rotLeft) transform.Rotate(0, -speed*Time.deltaTime, 0); 
    if (rotRight) transform.Rotate(0, speed*Time.deltaTime, 0); 
} 
:

나는 다음을 사용하여 그것을 해결

어떤 값이 Time.deltaTime 인 지 모른다는 것을 알고 있습니다. OnGUI - 그게 뭐죠? d가 마지막 OnGUI 이후의 시간이되었지만 확실하지 않습니다. 문제를 피하기 위해 나는 에 실제 회전을 배치하고 OnGUI과 통신하기 위해 두 개의 제어 논리 (rotLeftrotRight)를 사용했습니다.

관련 문제