I’m making a side-scrolling game, and I want to be able to hide the front walls of rooms when you enter them, and reveal them when you exit. I’ve written a script that is applied to a trigger that covers the area of the room, hiding the wall when the player enters, like so:
var fourthWall : GameObject;
var fadeTarget : float = 1;
var fadeSpeed : float = 4;
function Update () {
fourthWall.renderer.material.color.a = Mathf.Lerp(fourthWall.renderer.material.color.a, fadeTarget, Time.deltaTime * fadeSpeed);
}
function OnTriggerEnter( other : Collider ) {
if( other.name == "PlayerTrigger" ) {
Debug.Log("Entered "+gameObject.name);
fadeTarget = 0;
}
}
function OnTriggerExit( other : Collider ) {
if( other.name == "PlayerTrigger" ) {
Debug.Log("Exited "+gameObject.name);
fadeTarget = 1;
}
}
The problem is, I now have a room that isn’t a perfect rectangular shape. It’s sort of L-shaped. I’ve tried using a trigger mesh collider, using a mesh with the shape of the room, however this registers an exit call as soon as the player is fully inside the trigger. I’ve tried using compound colliders (a box collider, with another box collider as it’s child), however this registers the exit call when the player moves between the two colliders. How can I make a trigger area that is irregularly shaped, but treated as one continuous trigger? Thanks!