- Home /
Cannot implicitly convert type
public GameObject[] thisClient;
void OnCollisionEnter2D (Collision2D coll) {
if (coll.gameObject.name == "Client")
thisClient = coll.gameObject;
}
Cannot implicitly convert type UnityEngine.GameObject to UnityEngine.GameObject[]
Why it doesn't work?
Comment
Best Answer
Answer by KellyThomas · Jan 27, 2014 at 11:45 AM
Just needs this change:
//public GameObject[] thisClient;
public GameObject thisClient;
No. I need an array of objects. Every time of collision, if it is "Client", add it to array thisClient[]
Oh... In that case:
public List<GameObject> theseClients = new List<GameObject>();
void OnCollisionEnter2D (Collision2D coll) {
if (coll.gameObject.name == "Client")
theseClients.Add(coll.gameObject);
}
New error. The type or namespace name List
1' could not be found. Are you missing a using directive or an assembly reference?
List is in the System.Collections.Generic namespace, so add using System.Collections.Generic;
to the top of your script.
I think you need to replace wherever your calling "List" in your code to "theseClients"
$$anonymous$$eep where you declare theseClients as a list, but don't reference "List" in your script.