I am making an elevator that passes through the terrain. The character should be allowed to pass through the ground temporarily when he is within the sphere collider. The code is as follows:
using UnityEngine;
using System.Collections;
public class TerrainHole : MonoBehaviour {
public Collider player; // assign in inspector?
public Terrain terrain; // assign in inspector?
void OnTriggerEnter (Collider c) {
if (c.tag == "Player") {
Physics.IgnoreCollision(player.GetComponent<Collider>(), terrain.GetComponent<Collider>(), true);
}
}
void OnTriggerExit (Collider c) {
if (c.tag == "Player") {
Physics.IgnoreCollision(player.GetComponent<Collider>(), terrain.GetComponent<Collider>(), false);
}
}
}
By all accounts this should work, but I can't get any variation of it to work so far.
What am I doing wrong?