- Home /
Cannot convert 'UnityEngine.GameObject[]' to 'UnityEngine.GameObject'.
I understand the meaning of the error I'm just unsure of how to fix it so my script works. Here's a little part of my script
var pickableObject : GameObject;
function Update () {
pickableObject = GameObject.FindGameObjectsWithTag ("pickUp");
}
how could I get it so it's multiple objects? (If that makes sense)
Answer by Ekta-Mehta-D · Jan 02, 2015 at 11:22 AM
hii..
var pickableObject[] : GameObject;
function Update () {
pickableObject = GameObject.FindGameObjectsWithTag ("pickUp");
for(var i : int = 0 ; i < pickableObject.length ; i++)
{
var o : GameObject = pickableObject[i];
}
}
This will work.
This will list all object with tag "pickUp" .
Or if u have single object with tag "pickUp". u can use GameObject.FindGameObjectWithTag
Answer by tanoshimi · Jan 02, 2015 at 11:20 AM
GameObject.FindGameObjectWithTag ("pickUp");
not
GameObject.FindGameObjectsWithTag ("pickUp");
@tanoshimi that means it would only do one out of the multiple objects wouldn't it?
@Chickenator, change your pickableObject to an array:
var pickableObject[] : GameObject;
Well, yes, it's rather unclear from the limited code sample what your intention was! How many pickableObjects do you have, and what is this function meant to actually do with them?
@tanoshimi sorry I just wanted to see if I could get multiple objects into one variable. Next time I ask the question I will supply the whole script and try to explain a bit more in depth. Sorry if I wasted any time and @Landern yeah that works as well as the other answer, thanks
Your answer
Follow this Question
Related Questions
Comparing an object created with in-game gameobjects with some predefined model 0 Answers
Problem with adding number of Potions 1 Answer
How do you change size of an object by its units rather than scale? 1 Answer
Make gameobject appear on collision 1 Answer
How to spawn only one GameObject from a list of game objects? Please help. 1 Answer