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 /
avatar image
0
Question by alaricpetz · Sep 05, 2015 at 01:16 AM · gameobjecttriggerrenderingontriggerenterrender

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

I'm a new Unity user.

To make my scene perform better, I have switched the mesh renderer off for objects that don't necessarily need to be seen.

However, when the player enters a collider, I want those objects (assigned the tag "Appear") to have their meshes rendered so that they may become visible.

 using UnityEngine;
 using System.Collections;
 
 public class RenderTrig : MonoBehaviour {
     void OnTriggerEnter(Collider other) {
         GameObject Appear = GameObject.Find("Appear");
         (Appear).GetComponent<MeshRenderer>().enabled=true;
         }
 }

I tried to create what I thought would do the trick, called the script RenderTrig, and placed it on my collider, which I named TRIGGIFER. I know, however, that I'm doing something fatally wrong, but I don't know where my mistake lies. What do I need to do?

Thanks for your help in advance!

Comment
Add comment · Show 4
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 getyour411 · Sep 05, 2015 at 01:19 AM 0
Share

If you have other dynamic gameobjects in your game that might spring this trigger, you should put an "If(other.tag == "Player") in your OnTriggerEnter to ensure that "other" is indeed the player, what if it's a random chicken clucking by or anything.

Also add a debug line immediately after OnTriggerEnter like 'Debug.Log("Trigger sprung by: " + other.name); so you can ensure you are getting the trigger event you need.

avatar image alaricpetz · Sep 05, 2015 at 06:56 AM 0
Share

@getyour411 Isn't that Javascript?

avatar image getyour411 · Sep 05, 2015 at 06:58 AM 0
Share

Please do not post a comment or follow-up as an Answer. I converted that one for you but normally I just reject out of the mod queue cuz otherwise mods would do nothing but convert all day long.

Anyway, to your question - I suspect the little snippets I posted would be language agnostic but my intent was C# as that's what I use.

avatar image MewEight · Sep 05, 2015 at 06:59 AM 0
Share

Assu$$anonymous$$g your trigger does work.

You should be using this : FindGameObjectsWithTag

2 Replies

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

Answer by erfan · Sep 05, 2015 at 07:52 AM

You told that "Tag" not "Name". \n;

 GameObject.Find("GameObjectName");

Will Find An Object That It's name is "GameObjectName" You can use this.

   GameObject.FindGameObjectWithTag("MyTag");





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 thunderball001 · Jun 06, 2016 at 04:16 PM 0
Share

thank u. thats great!

avatar image
0

Answer by jmsearing · Sep 09, 2015 at 12:43 PM

Get an array of all objects with the tag "Appear". For each item in the array, set the mesh renderer to enabled = true.

 public class NameOfYourTriggersClass : MonoBehaviour {
     public GameObject[] visibleList;
 
     void OnTriggerEnter(Collider other) {
         //here's the script you need to create an array of gameobjects with tag: Appear
         if (visibleList == null) {
             visibleList = GameObject.FindGameObjectsWithTag("Appear");
         }
         //set each object's Mesh Rendere to enabled that appears in the list
         foreach (GameObject visible in visibleList) {
             visible.GetComponent<MeshRenderer>().enabled=true;
         }
 }

Haven't tested that but it should work as long as the trigger is actually triggering. Might get some errors or warning for not using the Collider of the triggering object.

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

6 People are following this question.

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

Related Questions

How come when the player runs into the coin it won't destroy? 1 Answer

Is there anyway to make an object impenetrable? 1 Answer

Navmesh agent problem 1 Answer

Destroy a specific object on trigger? 1 Answer

OnTriggerExit overwrites OnTriggerEnter 2 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