Unity3D에서 텍스쳐 바꿔치기 하는 방법

Unity3D 2012. 9. 25. 17:16
반응형

http://drago7.tistory.com/entry/Unity3D%EC%97%90%EC%84%9C-%ED%85%8D%EC%8A%A4%EC%B3%90-%EB%B0%94%EA%BF%94%EC%B9%98%EA%B8%B0-%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95


using UnityEngine;

using System.Collections;

 

public class Main : MonoBehaviour

{

 

    public GameObject prefab;

   

    private GameObject go;

    private bool flip;

    // Use this for initialization

    void Start()

    {

        flip = false;

        go = Instantiate(prefab) as GameObject;

        go.transform.position = new Vector3(0, 0, 0);

        go.animation.wrapMode = WrapMode.Loop;

    }

 

    // Update is called once per frame

    void Update()

    {

 

        if (Input.GetButtonUp("ChangeTexture"))

        {

            Debug.Log("Change Texture Button Up");

            int count = 0;

 

            if (flip)

            {

                flip = false;

                Debug.Log("Set Texture bytesTexture");

                foreach (SkinnedMeshRenderer smr

                    in go.GetComponentsInChildren<SkinnedMeshRenderer>(true))

                {

                    smr.material.SetTexture(

                        "_MainTex",

                        Resources.Load("bytesTexture") as Texture);

                    count++;

                }

            }

            else

            {

                flip = true;

                Debug.Log("Set Texture fuelCellTexture");

                foreach (SkinnedMeshRenderer smr

                    in go.GetComponentsInChildren<SkinnedMeshRenderer>(true))

                {

                    smr.material.SetTexture(

                        "_MainTex",

                        Resources.Load("fuelCellTexture") as Texture);

                    count++;

                }

            }

            Debug.Log("smr count is " + count);

        }

    }

}

반응형

'Unity3D' 카테고리의 다른 글

NGUI 한글 멘붕  (2) 2012.09.27
Tile Mapper  (0) 2012.09.26
Game Asset Website List (Free and Paid) (Textures, Models, Packs, etc)  (0) 2012.09.25
[Unity3D] Attributes 설명 모음  (2) 2012.09.25
Unity3D로 풀3D web mmorpg 만들기  (0) 2012.09.24
: