- Home /
How to make a game object appear, when another game object is clicked?
Sorry for the amateur question,
but for my Main Menu, when "Play" is pressed (which by the way is a Plane), i'd like two more planes to appear (preferably fade in). How exactly would I go ahead and do that?
@clunk47 - It says: "Fade GUITextures or anything that has a material." It does work with a planes. Note GUI and GUITexture are two different things.
I see, I didn't realize it was using renderer.material at first, only thought it was using GUI code. Good reference.
Answer by clunk47 · May 28, 2013 at 06:55 AM
A few ways to do this, I'll try to give you the simplest. Create your 3 planes in the editor. Make the plane you are going to click the parent of the 2 planes that will be invisible at first. Disable the mesh colliders for the invisibles. Then attach a script to your "main" plane, and use an [OnMouseDown][1] function. In this function, since your other two planes are the children, use [GetComponentsInChildren][2] to find the [MeshRenderer][3] components in each. On startup, set these to have 0 alpha in their color. Here's a C# example. Check the links I posted for more help.
using UnityEngine;
using System.Collections;
public class EXAMPLE : MonoBehaviour
{
MeshRenderer[] planes;
Color color;
void Start()
{
color = Color.grey;
color.a = 0;
planes = GetComponentsInChildren<MeshRenderer>();
foreach(MeshRenderer plane in planes)
{
plane.renderer.material.color = color;
}
}
void OnMouseDown()
{
StartCoroutine(FadeInChildren());
}
IEnumerator FadeInChildren()
{
while(true)
{
color.a+= 0.01f;
if(color.a >= 1.0f)
{
StopAllCoroutines();
}
foreach(MeshRenderer plane in planes)
{
plane.renderer.material.color = color;
}
print (color.a);
yield return new WaitForEndOfFrame();
}
}
}
Your answer
Follow this Question
Related Questions
Disable click in the Unity Splash-screen 0 Answers
i can't click the object build on pc vr game googlesamples 0 Answers
Texture-based mouseclick detection 1 Answer
Show graphic when using/click GameObject [C#] 0 Answers
Move another object 1 Answer