- Home /
 
The question is answered, right answer was accepted
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?
Did you mean Appear.GetComponent<$$anonymous$$eshRenderer>().enabled = true; in the OnTriggerEnter() ? 
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.
void start() to void Start()I missed that sorry. Also make sure one of your object has Rigidbody
is this script attached to objects with that Appear tag?
@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.
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.