Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mcfetrmatt · May 23, 2012 at 11:06 PM · triggereventbox collider

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hijinxbassist · May 23, 2012 at 11:18 PM 0
Share

@mcfetrmatt You can set your colliders isTrigger variable to true or false from script. http://unity3d.com/support/documentation/ScriptReference/Collider-isTrigger.html>isTrigger Ref. You will need a way to reference the other cube if you want to switch it from anothers isTrigger. So setup a var for the cube you want to switch the isTrigger on or off/ or collider enabled/disabled.

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by aldonaletto · May 23, 2012 at 11:16 PM

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; } }

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mcfetrmatt · May 24, 2012 at 12:24 AM 0
Share

@hijinxbassist @Aldo Naletto Thanks for the advice! I tried using: collider.enabled = false; because I just want to enable the main box collider. However no errors occur but my fountains do not start emitting particles.

The scene works, but I want to effectively hide the colliders and only have them appear once I hit a specific object. So you can walk over a fountain and it wont emit but after the object is hit they will emit after that event(or well the box colliders will be able to be interacted with at least).

avatar image aldonaletto · May 24, 2012 at 01:49 AM 0
Share

Setting a collider's isTrigger property doesn't affect anything but the collider behaviour. If the object has a particle effect, you must enable it when the trigger is entered. With the script below attached to the trigger, you can drag the fountain particles effect to the Fountain field in the Inspector:

var fountain: ParticleEmitter; // drag the fountain here

function OnTriggerEnter(other: Collider){ fountain.emit = true; // start emitting when trigger entered }

function OnTriggerExit(other: Collider){ fountain.emit = false; // stop fountain when trigger exited } NOTE: This works for the old particles; for the new Shuriken particles, the variable fountain should be declared ParticleSystem and fountain.Play() should be used to start emitting.

avatar image mcfetrmatt · May 24, 2012 at 03:17 AM 0
Share

$$anonymous$$y scene is say two game objects, two cubes. On of them is a box collider for the fountain particle system to start emitting. I only want the box collider for the particle system to start after I have collided with the 2nd game object. So even though you can walk through the trigger box at any time, I only want it to activate the fountain once you collide with it AFTER colliding with the 2nd box.

Here is my code that is attached to the Cube:

var fountain: GameObject; var splash: GameObject;

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

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

function OnTriggerExit(trigger:Collider){ yield WaitForSeconds(2); fountain.particleEmitter.emit = false; yield WaitForSeconds(2.5); splash.particleEmitter.emit = false; } Sorry I'm not sure if I have been clear enough in my intentions :) So is it possible to access the box collider part rather than the is trigger part? I'm not sure where I would put this either... Any idea of where I should look?

avatar image aldonaletto · May 24, 2012 at 11:50 AM 0
Share

I edited my question to include this trigger2-enabling-trigger1 behaviour.

avatar image mcfetrmatt · May 24, 2012 at 11:23 PM 0
Share

@aldonaletto You beauty! Thanks for all your help, it works perfectly! I had to adapt it a little to my scene as I have multiple instances but it works exactly how I wanted it to.

Thank you!

avatar image
0

Answer by dancinoman · Feb 25, 2016 at 08:25 AM

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;
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Door open after destroying all the enemies. 1 Answer

Is there an event/hook/trigger to sub to when a texture is applied to a gameObject in scene in editor mode? 1 Answer

Event Trigger For Key Pressed 4 Answers

Scoring System for Pinball 0 Answers

Make an object a trigger? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges