- Home /
activate other objects inside a different objects script
Is there a way to activate an object inside another objects script by using SetActive?
I have posted questions about this before but have got replies saying the question wasn't very clear so this is as clear as I can make it.
Thanks in advance!
Answer by Mikeywalsh · Sep 02, 2014 at 12:23 PM
You will receive an error if you try to set an object to active in your scene using GameObject.Find, as it will not be found(because it is inactive). You need to set up a reference to the object you wish to change in your script. Declare this at the top of your script:
public GameObject target;
You can then assign your target to this new variable in the inspector. Then all you have to do to enable/disable the object is:
target.SetActive(true);
//or
target.SetActive(false);
sorry for being a bit of a noob but would i put the public GameObject target; bit in the objects script that i am trying to activate?
um well i can't figure it out. could you explain? i'm kinda a noob.
This does not work for what i am trying to do.
i want to spawn an object that on collision activates 2 other game objects, but with this technique the GameObjects attached is removed on spawn, in other words i cant attach gameobjects already in the scene to a prefab waiting to be spawned
Answer by frogsbo · Sep 02, 2014 at 11:03 AM
hiya, there are many questions on this, you have to devide it into two steps, "access gameobject from other script"
make a variable equals to other object using drag or gameObject.Find or trigger, etc
and then set active
var hand = GameObject.Find("Hand");
hand.... set active
i d recommend following tornado twins worm game tutorial and then becoming familiar with searching clues to a question with different phrases and familiar with reference.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
OnMouseDown on Sprites (c#) 1 Answer
Can't create an Collider2D array? 1 Answer
A bunch of errors that I can't fix 1 Answer