- Home /
Click on object to activate another object
Hey guys,I am starting to learn more about unity.
Recently,I made a script that when you go into a trigger,another object activates/gets destroyed.
But I find that boring like you don't even need to click the mouse.
So i need a script that when you click on a gameobject's trigger or mesh,another gameobject appears.
Hopefully you can help me by finding a tutorial or a script!
Answer by awesomeface · Jan 11, 2014 at 08:16 AM
In object A, have this script attached
 var object : Transform;
 var clicked = false;
 
 function OnMouseEnter () {
 clicked = true;
 }
 
 function Update () {
 if(clicked){
 object.GetComponent(OtherScript).activated = true;
 }
 }
then in the object you want to have activated, attach a script called 'OtherScript' which has the variable 'activated' in it
Answer by MagicoCreator · Jan 11, 2014 at 07:46 AM
Answer by edcarlo · Jan 11, 2014 at 11:18 AM
 public GameObject otherObject;
 
 void OnMouseUp() // mouse click
 {
    otherObject.SetActive(true);
 }
 
 void OnTriggerEnter() // for trigger
 {
    otherObject.SetActive(true);
 }
Your answer
 
 
             Follow this Question
Related Questions
wall doesnt move after build 0 Answers
how to hide the mesh of the gameobject ? 1 Answer
Turning off renderer in other game object (C#) 2 Answers
C# Preserving GameObjects' Previous Meshes 1 Answer
At same positioned game objects collision detection 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                