- Home /
How to make an object appear after collision with an invisible object. I have tried a lot of ways, but still failed please help!
I have tried all of these ways, but still failed. I also tried setActive, but I just get errors using that. Please help I really need to understand this as I have multiple things I need to make appear after one another. Also the object I'm adding this script to is a fps controller. Side note the object LT_Birute_v1 is a solid and the object birutedialog is an invisble object, these codes I tried don't work with either. Sorry I'm really new at this. http://imgur.com/a/lVBTN This link will provide pictures with some clarification.
using UnityEngine;
using System.Collections;
public class appear : MonoBehaviour {
public GameObject myGameObject;
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "birutedialog")
{
myGameObject.GetComponent<MeshRenderer>().enabled = true;
myGameObject.GetComponent<Renderer>().enabled = true;
}
if(col.gameObject.name == "LT_Birute_v1")
{
myGameObject.GetComponent<MeshRenderer>().enabled = true;
myGameObject.GetComponent<Renderer>().enabled = true;
}
}
}
Answer by allenallenallen · Dec 19, 2015 at 08:16 AM
What is myGameObject? It's the only thing you are making visible here. And it seems like it has nothing to do with either biruteddialog or LT_Birute_v1
What exactly are you trying to do here? You said you wanted an object to appear after colliding with an invisible object, right? Does that mean both objects are invisible?
If anything, all you need to do is set the GameObject of the one you want to appear to enable renderer after collision.
When you write this line:
myGameObject.GetComponent<MeshRenderer>().enabled = true;
You are making the GameObject myGameObject MeshRenderer to be enabled. But only you know what that GameObject is, because you set it up in the editor.
I will upload a few pictures on imgur to help me explain it. Sorry for not being specific.
http://imgur.com/a/lVBTN Here is a link to some pictures for clarity.
Ah, I see. Everything's clear now.
if (col.gameObject.name == "birutedialog" || col.gameObject.name == "LT_Birute_v1")
{
myGameObject.GetComponent<Renderer>().enabled = true;
}
That should be all you need then.
For some reason it still does not work. Could I maybe please take a little bit of your time and ask you to make a few pictures where this code is used in action? Or maybe I can watch a video tutorial or something about it. Sorry for all of this asking for things...
Pretty much the same thing.
void OnTriggerEnter(Collider col)
{
if (col.gameObject.name == "birutedialog" || col.gameObject.name == "LT_Birute_v1")
{
myGameObject.GetComponent<Renderer>().enabled = true;
}
}