- Home /
[2d] hidden object gets visible in radar circle
Hey guys,
I hope the headline describes already quite good what I am looking for. I am quite new to unity and currently I develop a little arcade shooter and there should be hidden mines, that come visible when they hit the radar section of the space ship ... and they should not be seen directly at ones ... they should become slowly visible when they enter the radar area ... how can I archive this?
Hope for ur help ... Thx Applepie
Answer by $$anonymous$$ · Jun 04, 2015 at 12:04 PM
Hi Applepie,
[1] To achieve the mines becoming visible when they enter the radar, you can simply enable or disable the SpriteRenderer(assuming you are using this, or MeshRenderer if you are using that) accordingly.
[2] For the fading, I would set a bool on the mines that changes the alpha value of the material like so;
bool isVisible;
float alpha = 0;
void Update()
{
if(isVisible)
FadeIn();
}
void FadeIn()
{
Color prev = GetComponent<SpriteRenderer>.material.color;
if(alpha < 1)
alpha += 0.01f; //Change 0.01f to your liking
Color col = new Vector4(prev.r, prev.g, prev.b, alpha);
GetComponent<SpriteRenderer>().material.color = col;
}
Set isVisible to true when it enters the radar area.
Hope this helps.
Your answer
Follow this Question
Related Questions
Custom Joystick 4 direction (+) 0 Answers
Which Camera Rotation is Good While Making 2D Game? 0 Answers
Echolocation in 2D top down game 0 Answers
Inverting Position on One Axis 0 Answers
Unity 2D Multiplayer Spawning 0 Answers