Hey everyone, I recently converted from using Game Maker to Unity and I wanted to know how I would go about making it so I can toggle the solidity of a box(or any solid object) at the press of a button( lets say “S” for arguments sake). Help would be greatly appreciated.
You can set collider.isTrigger to true: the object’s collider becomes a trigger, and other objects pass through it. OnCollision events are no more sent - the trigger sends OnTrigger events instead.
NOTE: If the object has a rigidbody, set rigidbody.useGravity to false, or it will fall through the terrain like a rock!
You can just change the collider’s ‘enabled’ property to stop it from interacting with other colliders like:
void Update() {
if (Input.GetKeyDown(KeyCode.S)) {
collider.enabled = !collider.enabled;
}
}