• 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 Praquenome · Jun 05, 2015 at 04:11 PM · javascriptcollidertriggerobject

Enable objects to enter the trigger

Hello how are you? , the map of my game this very large with many details and this giving lag, so I tried do this script that activates objects when entering a trigger, more did not work alguem can help me?

 var Cena: GameObject;
 function OnTriggerEnter(otherObj: Collider){
     if (otherObj.tag == "Player"){
         Cena.SetActive.active = true ;
     } 
     else {
         Cena.SetActive.active = false ;
     }
 }
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 Hellium · Jun 05, 2015 at 04:17 PM 1
Share

What have you tried until now ?

  • Do your objects have a collision box ? (one object with the trigger mode activated, the other object with a rigid body)

  • Are you sure you enter the trigger ? (Debug.Log to test for example)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FirePlantGames · Jun 06, 2015 at 02:55 AM

Correct me if I'm wrong, but isn't GameObject.SetActive supposed to be like this

 GameObject.SetActive(true);

???

Comment
Add comment · Show 1 · 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 Gardes · Jun 06, 2015 at 03:30 AM 0
Share

You're right

avatar image
0

Answer by Gardes · Jun 06, 2015 at 03:19 AM

Try this:

  var Cena: GameObject;
  function OnTriggerEnter(otherObj: Collider){
      Debug.log("triggered"); // trigger works finally
      if (otherObj.tag == "Player"){
          Debug.log("Cena enabled"); // Cena got enabled, yay \o/
          Cena.SetActive(true);
      } 
      else {
          Debug.log("Cena disabled"); // Just to check it's not instantly disabled again
          Cena.SetActive(false);
      }
  }

Finally I don't know your scene, but if you got a big trigger platform for example, OnTriggerStay would be come in handy.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using a Single Collider to Detect Collisions with Multiple Colliders 3 Answers

Check if trigger collider is touching other trigger collider 2 Answers

Collision with renderer.enabled? 0 Answers

Activate Object with trigger and if leave then inactivate 2 Answers

Object won't collide with Player unless Player is moving 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