- Home /
Can't Activate a GameObject from Array
Hello,
I'm having major difficulty activating a GameObject from an array.
Code:
if (Input.GetKeyDown(KeyCode.V))
{
n++;
w[n].enabled = true;
Debug.Log(w[n].name);
}
The debug statement knows the name of the object, but never enables it.
Any help is appreciated. Thanks!
EDIT #1:
I've added a Debug statement to check the status of the GameObject, it's returning true, but it's definitely not active in the inspector or in the game view.
Answer by tormentoarmagedoom · Oct 18, 2018 at 02:59 PM
Good day. What is "w" ? a object? a component of an object?
enable is for components, to active/desactive a whole gameobject needs to use SetActive
w[n].SetActive(true);
Bye!
Yeah, thanks for this, I guess I just needed a fresh pair of eyes on it.
For clarification, w is a script that I used gameObject.GetComponent on. I was trying to enable the script, which was already on, but I wanted the Gameobject it was attached to.
Added this ins$$anonymous$$d:
w[n].gameObject.SetActive(true);
Works perfectly.
Thanks a lot!
Your answer
Follow this Question
Related Questions
How would I find the name of all game objects in a c# List 1 Answer
What is the best way to instatiate an array of connected GameObjects? 0 Answers
How to select an Game Object from an Item List 0 Answers
[C#] Sorting a List of Gameobjects Alphabetically 2 Answers
How to put gameObjects to the list? 4 Answers