- Home /
Fade texture on collision/trigger with certain tag or layer?
We're developing a storm system and we have a two cylindrical layer systems that handle the rain and mist effects. We need them to fade on collision or trigger when entering a certain layer or tag (a house or inside area) then fade back in when out of the trigger area, but the collision can't interfere with the players motion. It has to just act as just a trigger.
Is there anyway to do this? If you guys could help us out that'd be great thanks.
Something like this which doesn't seem to work? And doesn't handle tags so we're not really sure how to go about this..
var glowColor : Color = Color.grey; private var dot : float = 0.5f;
function Update () {
if (collider.isTrigger == true) renderer.sharedMaterial.SetColor ("_TintColor", glowColor * dot); }
Answer by aldonaletto · Feb 04, 2012 at 12:04 AM
I'm not sure if I understood exactly what you want to do. If you have rain and mist generators attached to the player, and want to fade them when the player enters some selected volumes, you can use something like this (player script):
var inTrigger: int = 0; // is > 0 when inside any "FadeArea" trigger var rain: GameObject; // rain generator var mist: GameObject; // mist generator
function OnTriggerEnter(other: Collider){ if (other.tag == "FadeArea"){ // if entering a FadeArea trigger... inTrigger++; // increment the inTrigger counter } }
function OnTriggerExit(other: Collider){ if (other.tag == "FadeArea"){ // if leaving a FadeArea trigger... inTrigger--; // decrement the inTrigger counter } }
function Update () { var fade: float = 1.0; // fade factor: is 1.0 for normal color... if (inTrigger > 0) fade = dot; // and "dot" when faded rain.renderer.sharedMaterial.SetColor ("_TintColor", glowColor fade); mist.renderer.sharedMaterial.SetColor ("_TintColor", glowColor fade); } This script will fade the color whenever the player enters a trigger tagged "FadeArea". A counter is used to handle overlapping triggers: inTrigger is zero only when the object is outside all "FadeArea" triggers.
Thank you very much for this it helps a lot. Can't really get it working but we'll try to figure it out. It keeps saying there is no collider on mistsystem when there is. Do I deactivate the collision, leave the trigger on or off? How do I make the make player be able to walk threw trigger zones?
Thanks again!
To cause a OnTrigger event, at least one of them (the moving object or the trigger) must be a rigidbody or CharacterControler - the collider alone isn't enough. At least in trigger->character collisions, a kinematic rigidbody attached to the trigger works fine.
Answer by Berenger · Feb 03, 2012 at 11:48 PM
I believe you are looking for this : http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html
Your answer
Follow this Question
Related Questions
Fire Collision detection 1 Answer
How come the Trigger teleports when its not supposed to! 1 Answer
Trigger not detecting tag 1 Answer
Ignore collision on tag not working 2 Answers
OnTriggerEnter Collision 1 Answer