- Home /
Can requirecomponent specify IsTrigger on a collider?
Each occlusion portal in my game is used by a separate system, and in order to keep a list of which portals are near the player I'm using OnTriggerEnter and OnTriggerExit to detect when a large trigger collider attached to the player enters each portal. For this to work, each portal needs collision detection, and it's trivial to use RequireComponent to ensure that every portal has a collider on it. However, I specifically need each collider to be a trigger collider (so the player doesn't slam into an invisible wall), and I don't trust myself to manually set hundreds of colliders in the inspector without forgetting one. I can always just run something in Awake() to manually GetComponent each portal and set portal.IsTrigger = true, but that's clunky as well- is there any way I can use requirecomponent to automatically set IsTrigger when the collider is added?
Answer by Eric5h5 · Nov 14, 2014 at 05:23 AM
No, but you can use the Reset function.
function Reset () {
GetComponent(Collider).isTrigger = true;
}