이전 메터리얼 저장
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;
// Start is called before the first frame update
void Start()
{
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;
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("1"))
{
SetObjectToTransparent();
}
if (Input.GetKeyDown("2"))
{
SetObjectReverseMat();
}
}
}
댓글 없음:
댓글 쓰기