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 /
This question was closed Sep 11, 2015 at 03:56 AM by getyour411 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by alaricpetz · Sep 06, 2015 at 07:22 PM · c#colliderontriggerentertagsmeshrenderer

I'm trying to adjust tagged objects meshrenderer in C# code.

I want the objects with the tag "Appear" to be invisible (meshrenderer off) on game start.

But I want them to become visible once the player has passed through a trigger.

 using UnityEngine;
 using System.Collections;
 
 
 public class Trig1 : MonoBehaviour {
     public GameObject Appear;
 
     void start()
     {
     Appear = GameObject.FindGameObjectWithTag ("Appear");
     Appear.GetComponent<MeshRenderer> ().enabled = false;
     }
 
     void OnTriggerEnter(Collider other) 
     {
     Appear.GetComponent<MeshRenderer>().enabled = false;
     Debug.Log ("Object has entered the trigger!");
     }
 }


Could you help identify what I'm doing wrong?

Comment
Add comment · Show 5
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 Positive7 · Sep 06, 2015 at 07:33 PM 1
Share

Did you mean Appear.GetComponent<$$anonymous$$eshRenderer>().enabled = true; in the OnTriggerEnter() ?

avatar image alaricpetz · Sep 07, 2015 at 03:46 AM 0
Share

@Positive7

Yes. But it still doesn't work when I change it to that.

Let me try to guess what I'm doing wrong.

1: I failed to make the objects tagged with "Appear" a variable that I can call. 2: The triggers or colliders doesn't work for some reason. 3: Some kind of other syntax error, but I don't get any error messages.

I don't have any apparent errors, but the code simply doesn't do what I want it to. I just want to make the objects tagged with "Appear" tag to be invisible but then turn visible when a player goes into a trigger.

avatar image Positive7 · Sep 07, 2015 at 02:09 PM 0
Share

void start() to void Start()I missed that sorry. Also make sure one of your object has Rigidbody

avatar image hexagonius · Sep 07, 2015 at 09:04 PM 0
Share

is this script attached to objects with that Appear tag?

avatar image alaricpetz · Sep 08, 2015 at 09:17 AM 0
Share

@hexagonius No, it's attached to the hitbox that the player will pass through that will trigger all the objects tagged with "Appear" to appear.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by alaricpetz · Sep 11, 2015 at 03:46 AM

A friend walked me through making the code that I wanted.

 using UnityEngine;
 using System.Collections;
 public class TRIGGIFER : MonoBehaviour {
     
     public GameObject[] visibleList;
 
     void Start(){
     visibleList = GameObject.FindGameObjectsWithTag("Appear");
 
     foreach (GameObject child in visibleList)
     {
     child.GetComponentInChildren<Renderer>().enabled=false;
     }
     }
     
     void Update(){}
     
     void OnTriggerEnter(Collider other) {
     Debug.Log ("Success");
     foreach (GameObject child in visibleList)
     {
     child.GetComponentInChildren<Renderer>().enabled=true;
     }
 }}


For future viewers.

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make gameObject make only one collision 1 Answer

How to have a score counter increment in OnTriggerEnter 1 Answer

onEnterCollider returns Collider 1 Answer

Set material of child that enter the collider. 1 Answer

100 OnTriggerEnter Or Tags each player too much? 3 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