2016-08-19 2 views
1

저는 비디오 게임을 화합하고 있으며 레벨 선택을 위해 GameObject의 x와 y 위치를 버튼의 x와 y 위치로 설정해야합니다.GameObject의 x와 y 위치를 어떻게 지정합니까?

내가 시도이

if (gameObject.CompareTag("Level1")) { 

     float xPos = gameObject.transform.position.x; 
     float yPos = gameObject.transform.position.y; 

     levelWindow.SetActive(true); 
     levelTitle.text = "One- Dunes of Coral"; 
     levelDescription.text = "Begin your ocean voyage in the safe haven of the Hawaiian coral reefs..."; 
     levelWindow.transform.position.x = xPos; 
     levelWindow.transform.position.y = yPos; 
} 

코드 -하지만 this-

자산/스크립트/LevelTapScript.cs (21,39)이 같은 오류 얻을 : 오류 CS1612이 : 수정할 수를 값 유형 반환 값은 'UnityEngine.Transform.position'입니다. 임시 변수에 값을 저장 고려

내 질문에 내가 x와 levelWindow의 y 위치 (게임 객체 인) 내 X 좌표와 Y 좌표가 수레를 사용하여 설정하는 방법 은? 고맙다 - 조지 :

답변

2

, 임시 Vector3 변수를 생성 x 축이 다음 다시 Transform.position에 할당 수정 : 당신이해야 할 일은 같은 것이있다.

if (gameObject.CompareTag("Level1")) 
    { 

     float xPos = gameObject.transform.position.x; 
     float yPos = gameObject.transform.position.y; 

     Vector3 newPos = new Vector3(xPos,yPos,0); 

     levelWindow.SetActive(true); 
     levelTitle.text = "One- Dunes of Coral"; 
     levelDescription.text = "Begin your ocean voyage in the safe haven of the Hawaiian coral reefs..."; 
     levelWindow.transform.position = newPos; 
     levelWindow.transform.position = newPos; 
    } 

이렇게하면 z pos가 0이됩니다.

1

두 가지 :

, 유니티 질문, 당신은 직접 변환의 위치 값을 설정할 수 없습니다,

https://gamedev.stackexchange.com/을 사용하는 것이 좋습니다. 당신은이

levelWindow.transform.position = new Vector3(xPos,yPos,0); 
+0

와우. 나는 너무 어리 석다. 나는 그것을 잊었다는 것을 믿을 수 없다. 또한 GameDev 사용을 고려할 것입니다. 감사 :) –

관련 문제