- Home /
cannot convert UnityEngine.Gameobject to GameObject - What's the difference?
So I want to add a gameObject to a list when the collider triggers. So I add other.gameObject to get the gameObject of the collider. But then it says that other.gameObject is of type UnityEngine.GameObject and my list is containing the type GameObject. What is the difference?
List<GameObject> possibleItemsToPickup = new List<GameObject>();
if (other.gameObject.CompareTag("Item"))
{
possibleItemsToPickup.Add(other.gameObject);
Debug.Log("added Item");
}
This is just extracts of the code.
Answer by Bunny83 · Apr 15, 2017 at 12:26 PM
The problem is that you have defined your own class named "GameObject". You should avoid using the same class / fie names as Unity uses for it's built-in classes.
If you still want to do this, you have to specify the full class name everytime you want to use the GameObject class of Unity:
List<UnityEngine.GameObject> possibleItemsToPickup = new List<UnityEngine.GameObject>();
Your answer
Follow this Question
Related Questions
How do I get a material from a GameObject? 1 Answer
Character animation problem 1 Answer
objects in the same array wont move 0 Answers
Transport objects between scenes. 1 Answer
How you find an Object 1 Answer