How to enable the box collider tick box on a trigger event

Hi there,

I am unable to find a solution to this myself so I was hoping I could get a answer here.

Seen as when you turn Is Trigger off you are unable to walk through the Cubes any more, Is there a way to access the Inspector panel via scripting? Does anyone know how I could enable the Box Collider of the Cubes after I collide with another object?

I’m not sure exactly how to work this so I’m having trouble finding a solution, hope this Makes sense

Matthew

You can set a collider to trigger via script with the property collider.isTrigger: just set it to true (trigger) of false (solid collider).

collider.isTrigger = true; // convert collider in trigger

collider.isTrigger = false; // convert back to collider 

EDITED: Ok, so you have two box triggers: trigger 1 activates the particle emitters, but only when the player has passed the trigger 2, right? If this is correct, I think you should use a boolean flag set by trigger 2 that enables the particle emitters in trigger 1. A simple method is to call a function in trigger 1 when the player enters trigger 2: this function sets the boolean variable that enables the particles in trigger 1 - like this:

Trigger 2 script:

var trigger1: GameObject; // drag trigger1 object here

function OnTriggerEnter(other: Collider){
  // call EnableTrigger(true) in trigger 1
  trigger1.SendMessage("EnableTrigger", true); 
}

Trigger 1 script:

var fountain: GameObject;
var splash: GameObject;
var enable: boolean = false; // boolean flag: enable trigger 1 when true

function Awake(){
  fountain.particleEmitter.emit = false;
  splash.particleEmitter.emit = false;
}

// function called by trigger2 via SendMessage:

function EnableTrigger(onOff: boolean){
  enable = onOff;
}

function OnTriggerEnter(trigger: Collider){
  if (enable){
    fountain.particleEmitter.emit = true;
    splash.particleEmitter.emit = true;
  }
}

function OnTriggerExit(trigger:Collider){
  if (enable){
    yield WaitForSeconds(2);
    fountain.particleEmitter.emit = false;
    yield WaitForSeconds(2.5);
    splash.particleEmitter.emit = false;
  }
}

Newer version: You have to Get your component that has the same name on the game object inspector. Like this:

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {

private PolygonCollider collider;   //The exact collider Component name

void Start()
{
collider = GetComponent<PolygonCollider> ();
}

void Update ()
{
 collider.isTrigger = false;
}