Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by xitric · Oct 23, 2016 at 03:05 PM · c#triggerplayerobjectshide

How do I hide/show an object, when the player enters a trigger zone?

The guests: "Player, MeshTrigger and HiddenObject"

So the mesh trigger is working. It logs in the console when the player moves through it. (Code below!) But... how can I now make it so that when the player enters/leaves the MeshTrigger collider, an object will appear/disappear?

If it helps, the object is to be an in game "UI element" with their own trigger events.

 using UnityEngine;
 using System.Collections;
 
 public class worldTrigger : MonoBehaviour {
     void OnTriggerEnter (Collider other) {
         if (other.CompareTag ("Player")) {
             Debug.Log ("Player Has Entered");
         }
     }
     void OnTriggerStay (Collider other) {
         if (other.CompareTag ("Player")) {
             Debug.Log ("...");
         }
     }
     void OnTriggerExit (Collider other) {
         if (other.CompareTag ("Player")) {
             Debug.Log ("Player Has Exited");
         }
     }
 }

Got it from here: https://unity3d.com/learn/tutorials/topics/physics/colliders-triggers

I'm sorry and thanks. :) I'm very new to C#. Please be mean so I can learn.

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
Best Answer

Answer by xitric · Oct 23, 2016 at 06:22 PM

lol nvm. Figured it out. So I named the hidden object hidey.

edit: instead of gameObject.GetComponent().enabled = false;, use gameObject.SetActive(false); to hide everything!!!

 using UnityEngine;
 using System.Collections;
 
 public class worldTrigger : MonoBehaviour {
 
     private GameObject hidey;
     void Start() {
         hidey = GameObject.Find("hidey");
         hidey.gameObject.SetActive(false);
     }

     void OnTriggerEnter (Collider other) {
         if (other.CompareTag ("Player")) {
             hidey.gameObject.SetActive(true);
         }
     }
 
     void OnTriggerExit (Collider other) {
         if (other.CompareTag ("Player")) {
             hidey.gameObject.SetActive(false);
         }
     }
 }








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 MTDues · Aug 04, 2017 at 01:16 AM 0
Share

The script disables every Tag named Player, Even the ones didnt Enter the trigger

how to make it disappear only the "Player" which Entered Trigger ??

avatar image MTDues · Aug 04, 2017 at 01:29 AM 0
Share

and Also i would like to know how to reverse this script

For example Like Activating all Objects tagged "Player2" cuz i couldnt reverse it, i tried

avatar image
0

Answer by MTDues · Aug 04, 2017 at 12:57 AM

put this script inside what?

may u explain what u did ?

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

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

Related Questions

How to stop a player from entering a trigger 0 Answers

OnTrigger Problems Between Colliders Issue 1 Answer

Player Can Not get off platform 1 Answer

Help on how to code crouching? 0 Answers

Image Pop Up,Fade in and Fade out OnTrigger 0 Answers


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