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
0
Question by Peanut97 · Dec 15, 2012 at 04:11 PM · movementgameobjecttriggerontriggerenter

OnTriggerEnter Help?

Hello everybody,

I am currently working on a horror game in unity and I ran into a problem. If anyone can help me out with this, I would really appreciate it! In the game, the Player is going to be walking through a hall and there will be a tigger zone (OnTriggerEnter) right before an intersection in the hallway. When the player hits that trigger zone, a gameobject will rush through the intersection (In front of you.) So really what I'm asking is, Is there a way to make a gameobject move when you enter a trigger (OnTriggerEnter)? If there is a way to do this, I would really appreciate some help. If there isn't a way to do this, do any of you guys have a different solution? Thanks for your help! I REALLY appreciate it!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by jdams · Dec 15, 2012 at 05:28 PM

On the game object that is moving simply add a script called runningScript with a boolean variable. Like this:

var run : boolean;

function Update(){ if(run){ //script here to move the object. } }

Then on the trigger setup this script:

var runningObject : GameObject;

function OnTriggerEnter(){ runningObject.GetComponent("runningScript").run = true; }

In the Inspector Panel Drag and drop the running object into the "RunningObject" area of the trigger script.

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
avatar image
0

Answer by fafase · Dec 15, 2012 at 04:28 PM

the idea is to wrap the behavior of your passing guy into a boolean:

WaitingScript.cs

 public bool isInTrigger = true;
 
 void Update(){
     if(inInTrigger)//Get The guy going
 }

On the trigger box:

 WaitingScript script;
 
 void Start(){
    script = GameObject.Find("WaitingGuy").GetComponent<WaintingScript>()
 }
 
 void OnTriggerEnter(Collider ohter){
    if(other.gameObject.tag=="Player")script.isInTrigger = true;
 }

The same in unityScript:

WaitingScript.js

 var isInTrigger:boolean=true;
 
 function Update(){
     if(inInTrigger)//Get The guy going
 }

On the trigger box:

 var script:WaitingScript;
 
 function Start(){
    script = GameObject.Find("WaitingGuy").GetComponent(WaintingScript)
 }
 
 function OnTriggerEnter(other:Collider){
    if(other.gameObject.tag=="Player")script.isInTrigger = true;
 }
Comment
Add comment · Show 2 · 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 Peanut97 · Dec 15, 2012 at 04:45 PM 0
Share

So just to be 100% clear, I put the WaitingScript.cs on the guy (who will rush past the camera) and the "On the trigger box" script on the Trigger box?

avatar image fafase · Dec 15, 2012 at 04:52 PM 0
Share

Yep. Your player does not get anything here. I guess you know about the trigger box, it should be an empty game object with a collider box set to isTrigger.

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

11 People are following this question.

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

Related Questions

Object moving OnTriggerEnter, please help?! 2 Answers

Moving object with a trigger? 0 Answers

How do I make all game objects with a certain tag appear on trigger enter? (C#) 2 Answers

Why won't the coin destroy when hit? 0 Answers

Moving objects using raycasting? 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