- Home /
Solved problem by myself
How to make 3d object with a lot of meshes partly transparent for 1 player and for other fully transparent
Hello everyone. I hope you can help me. So i'm creating 3d multiplayer game. And I faced with couple of issues. The first issue: I have 3d model imported from blender, it consists of a lot of different meshes. How to make this model transparent? The second issue: I need this model becomes partly transparent for player who is using this model and for other players fully transparent. P.S.: I found in internet only the way of changing alpha of material of object. So in this case as I understand I would need to change alpha of all materials which are refered to model. But I'm afraid that when I change alpha of material, other players who are using same model also will become trasparent. The task is to get effect same as in mobile game "Brawl Stars" when the player is hidining in bushes, so that player becomes invisible for others and partly visible for himself. Thank you in advance!!
Solved problem by myself by writing following script: using UnityEngine;
public class SaltOrSugar : MonoBehaviour { private Color[] startPlayerColor; private Color startObjectColor; private Material start; private Renderer [] hero;
public float transparencyOfplayer = 0.5f; public float transparencyOfobject = 0.5f;
private void OnTriggerEnter(Collider other)
{
startPlayerColor = new Color[other.gameObject.transform.childCount];
for (int i = 0; i < other.gameObject.transform.childCount; i++)
{
if(other.gameObject.transform.GetChild(i).tag != "MainCamera")
startPlayerColor[i] = other.gameObject.transform.GetChild(i).gameObject.GetComponent<Renderer>().material.color;
}
startObjectColor = gameObject.GetComponent<Renderer>().material.color;
if (other.gameObject.tag == "Hero")
{
start = gameObject.GetComponent<Renderer>().material;
Color starts = start.color;
starts.a = transparencyOfobject;
start.color = starts;
hero = other.gameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer mat in hero)
{
Material heromat = mat.material;
Color hero1 = heromat.color;
hero1.a = transparencyOfplayer;
heromat.color = hero1;
}
}
}
private void OnTriggerExit(Collider other)
{
int counter = -1;
if (other.gameObject.tag == "Hero")
{
start.color = startObjectColor;
foreach(Renderer mat in hero)
{
counter++;
Material heromat = mat.material;
heromat.color = startPlayerColor[counter];
}
}
}
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Alpha Transparent Shader hides NGUI fonts 0 Answers
GameObject not destroyed on Collision on Standalone - multi 0 Answers
Transparent shader with depth writes 3 Answers
Realtime game using game sparks 1 Answer