Last active
April 24, 2020 02:16
-
-
Save DongguemYoo/892258a02a313c843727c8882026b387 to your computer and use it in GitHub Desktop.
투명화
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
이전 메터리얼 저장 | |
{ | |
Material[] newMat; | |
newMat = Equip.GetComponent<MeshRenderer>().materials; | |
Arrow.GetComponent<Panel_TutoInfo>().mat_Prev = newMat; | |
} | |
void SetTargetObjectToTransparent() | |
{ | |
//Debug.Log("투명"); | |
MeshRenderer ren; | |
Material[] mats; | |
ren = TargetObj.GetComponent<MeshRenderer>(); | |
mats = ren.materials; | |
for (int i = 0; i < mats.Length; i++) | |
{ | |
mats[i] = mat_Transparent; | |
} | |
ren.materials= mats; | |
//mats[0] = mat_Transparent; | |
} | |
void SetTargetObjectToReverseMat() | |
{ | |
//Debug.Log("불투명"); | |
MeshRenderer ren; | |
Material[] mats; | |
ren = TargetObj.GetComponent<MeshRenderer>(); | |
mats = ren.materials; | |
for (int i = 0; i < mats.Length; i++) | |
{ | |
mats[i] = mat_Prev[i]; | |
} | |
ren.materials = mats; | |
} | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ObjectTransparentManager : MonoBehaviour | |
{ | |
public Material mat_Transparent; | |
public MeshRenderer[] targetrenders; | |
public Dictionary<int, Material[]> dic_prevMats = new Dictionary<int, Material[]>(); | |
//public Material[,] prevMats; | |
void Start() | |
{ | |
//자식으로 있는 모든 객체의 meshRenderer를 찾아온다 | |
targetrenders = GetComponentsInChildren<MeshRenderer>(); | |
InItMeshs(); | |
} | |
public void InItMeshs() | |
{ | |
for (int i=0;i< targetrenders.Length;i++) | |
{ | |
Material[] tempMat; | |
tempMat = targetrenders[i].materials; | |
dic_prevMats.Add(i, tempMat); | |
} | |
} | |
public void SetObjectToTransparent() | |
{ | |
for (int i = 0; i < targetrenders.Length; i++) | |
{ | |
Material[] mats; | |
mats = targetrenders[i].materials; | |
for (int x = 0; x < mats.Length; x++) | |
{ | |
mats[x] = mat_Transparent; | |
} | |
targetrenders[i].materials = mats; | |
} | |
} | |
public void SetObjectReverseMat() | |
{ | |
for (int i = 0; i < targetrenders.Length; i++) | |
{ | |
Material[] mats; | |
mats = targetrenders[i].materials; | |
mats = dic_prevMats[i]; | |
targetrenders[i].materials = mats; | |
} | |
} | |
void Update() | |
{ | |
if (Input.GetKeyDown("1")) | |
{ | |
SetObjectToTransparent(); | |
} | |
if (Input.GetKeyDown("2")) | |
{ | |
SetObjectReverseMat(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment