2월, 2013의 게시물 표시

[Unity] C#에서 자바스크립트 사용하기

유니티 상에서 c#과 자바스크립트를 연동하고 싶다면 Standard Assets 폴더안에 스크립트를 넣고 실행 시키면 사용할 수 있게된다. Standard Assets 폴더안에 다른 폴더를 만들어 놔도 사용이 가능하다 If C# or Java file located in Standard Assets folder, You can compatible with C# and Java Script.

유니티 상속 관계 를 코드에서 해체 하기

transform.DetachChildren 은 부모와 자식간의 연결을 끊는다. using UnityEngine; using System.Collections; public class example : MonoBehaviour{     void Awake(){            transform.DetachChildren();            Destroy(gameObject);      } } 위 코드는 부모만 제거하고 자식들은 유지하기 원하는 경우 사용할수 있다. Transform.Parent 는 부모를 변환한다. using UnityEngine; using System.Collections; public class example : MonoBehaviour {     public Transform cameraTransform = Camera.main.transform;     void Awake() {         cameraTransform.parent = transform;         cameraTransform.localPosition = -Vector3.forward * 5;         cameraTransform.LookAt(transform);     } } 또는 transform.parent = null;로 사용할 수 있다.

Unity 유니티 그림파일 순서대로 읽어오기, 반복문으로 버튼 생성

for(k=0;k<=5;k++) { iFile[k] = "file://"+ Application.dataPath +"/Source/Question/1/L1S1A"+(k+1)+".png"; tL[k]= new WWW(iFile[k]); tD[k]= new Texture2D(64, 64); tL[k].LoadImageIntoTexture(tD[k]); bP[k]=(k+3)*100; } 이전에 설명되었던 Apllication.dataPath를 활용했습니다. 그림파일에 숫자로 규칙성을 만들어주어 반복문으로 해결하게 했습니다. (L1S1A1.png~L1S1A5.png까지 ) for(k=0;k<=5;k++) {  if (GUI.Button (Rect (bP[k],550,100,50),tD[k]))    {           Userselect=k+1;                  } } 위 코드는 버튼을 생성할때 반복문을 사용했습니다.

Unity 유니티 Application.dataPath

Application.dataPath 게임 경로를 문자열로 반환합니다. Unity Editor <프로젝트 폴더의 경로>/Assets Mac player <플레이어 앱 번들의 경로>/Contents iPhone player <플레이어 앱 번들의 경로>/<AppName.app>/Data Win player <EXE파일이름_Data 폴더의 경로> Web player (or Dashboard widget) 플레이어 데이터 파일 폴더의 절대(Absolute) URL (실제 데이터 파일 이름 없이) 출처-유니티 레퍼런스

Unity 유니티 - 이미지 파일 불러온후 텍스쳐에 넣기

Java var tDynamicTx : Texture2D ; var tLoad :WWW ; var images : String ; images = "file://"+ Application.dataPath +"Test.jpg"; tLoad= new WWW(images); tDynamicTx= new Texture2D(64, 64); tLoad.LoadImageIntoTexture(tDynamicTx); C# public Texture2D tDynamicTx; public WWW tLoad; public string images; images = "file://"+ Application.dataPath +"Test.jpg"; tLoad= new WWW(images); tDynamicTx= new Texture2D(64, 64); tLoad.LoadImageIntoTexture(tDynamicTx); 출처 -  Http;//answers.unity3d.com (http://answers.unity3d.com/questions/263177/www-problem-get-image-.html?sort=oldest)