'2014/01/26'에 해당되는 글 6건

  1. 2014.01.26 유니티 관련 컴포넌트 추가 방법
  2. 2014.01.26 유니티 스크립트 코드로 컴포넌트 삭제하기
  3. 2014.01.26 Unity3D 스프라이트 렌더러 색 변경
  4. 2014.01.26 Unity2D 스프라이트 렌더러 동적할당
  5. 2014.01.26 유니티 코루틴 관련 함수(대화 관련)
  6. 2014.01.26 블로그 변경.

유니티 관련 컴포넌트 추가 방법

|
using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {
    public SphereCollider sc;
    void Example() {
        gameObject.AddComponent("FoobarScript");
        sc = gameObject.AddComponent("SphereCollider") as SphereCollider;
    }
}


Trackback 0 And Comment 0

유니티 스크립트 코드로 컴포넌트 삭제하기

|


리지드 바디 컴포넌트 삭제 하는 방법


Rigidbody2D tmp = GetComponent<Rigidbody2D>();

Destroy(tmp);


모든 컴포넌트는 이런식으로 삭제가 가능하다.


Trackback 0 And Comment 0

Unity3D 스프라이트 렌더러 색 변경

|

private SpriteRenderer renderer;


renderer  = mole.GetComponent<SpriteRenderer> ();

renderer.color = new Color(0f, 0f, 0f, 1f); // Set to opaque black

Trackback 0 And Comment 0

Unity2D 스프라이트 렌더러 동적할당

|

Resource에서 Sprite 로딩.

SpriteRenderer spr = GetComponent<SpriteRenderer>();
spr.sprite = Resources.Load<Sprite>("path/name");


Trackback 0 And Comment 0

유니티 코루틴 관련 함수(대화 관련)

|
출처 : http://www.unitystudy.net/bbs/board.php?bo_table=writings&wr_id=43


코루틴용 데이터

엔진이 수행하는 기능

yield return null

다음 프레임까지 대기

yield return new WaitForSeconds(float)

지정된 초 만큼 대기

yield return new WaitForFixedUpdate()

다음 물리 프레임까지 대기

yield return new WaitForEndOfFrame()

모든 렌더링작업이 끝날 때까지 대기

yield return StartCoRoutine(string)

다른 코루틴이 끝날 때까지 대기

yield return new WWW(string)

웹 통신 작업이 끝날 때까지 대기

yield return new AsyncOperation

비동기 작업이 끝날 때까지 대기 ( 씬로딩 )



순차적 수행 가능







public class DialogExample : MonoBehaviour {

   

    bool showDialog = false;

    string answer = "";

   

    IEnumerator Start()

    {

        yield return StartCoroutine("ShowDialog"); //다른 코루틴이 끝날 때까지 대기

        yield return StartCoroutine(answer);

    }

   //answer 에 값이 들어가기 전까지는 코루틴이 끝나지 않음

    IEnumerator ShowDialog()

    {

        showDialog = true;

        do

        {

            yield return null;

        } while(answer == "");

       

        showDialog = false;

    }

   

    IEnumerator ActionA()

    {

        Debug.Log ("Action A");

        yield return new WaitForSeconds(1f);

    }

 

    IEnumerator ActionB()

    {

        Debug.Log ("Action B");

        yield return new WaitForSeconds(2f);

    }

   

    void OnGUI()

    {

        if(showDialog)

        {

            if(GUI.Button(new Rect(10f, 10f, 100f, 20f), "A"))

            {

                answer = "ActionA";  

            } else if(GUI.Button(new Rect(10f, 50f, 100f, 20f), "B")) {

                answer = "ActionB";

            }

        }

    }

   

}




Trackback 0 And Comment 0

블로그 변경.

|

블로그 주소 변경 및 디자인 전체적으로 전부 다 변경.

전부 Unity3D 관련 자료들을 다룰 예정임.

참고 사이트 및 스크립트 관련 기능 위주로 포스팅 할 예정



Trackback 0 And Comment 0
prev | 1 | next