Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'

using UnityEngine; using System.Collections;

public class NewBehaviourScript : MonoBehaviour { public GameObject aaa; public GameObject[] aa = new GameObject[5]; public Vector3[] haha = new Vector3[] { new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(2,0,0), new Vector3(4,0,0) };

 void Start () 
     for(int i = 0; i < 4; i++)
         aa[i] = Instantiate(aaa, haha[i], transform.rotation);


Unity told me that :

Assets/NewBehaviourScript.cs(13,25): error CS0266: Cannot implicitly convert type "UnityEngine.Object" to "UnityEngine.GameObject". An explicit conversion exists (are you missing a cast?)

I don't know what to do &=(

more ▼

asked Jan 08, 2011 at 03:37 AM

avatar image

xiumo hui
12 5 6 9

I got to hand it to you, you got funny variables.

Jan 08, 2011 at 10:13 AM Statement

just missing "aha" ...

Jan 09, 2011 at 04:22 AM yoyo
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The function Instantiate returns an Object. So your code for instantiating should be:

aa[i]=Instantiate(aaa,haha[i],transform.rotation) as GameObject; 



I like the first way better, but they are both the same

more ▼

answered Jan 08, 2011 at 03:45 AM

avatar image

1.1k 30 29 51

Jan 08, 2011 at 03:55 AM Jessy

Oh. Never knew that.

Jan 08, 2011 at 04:23 AM fireDude67
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 08, 2011 at 03:37 AM

Seen: 38378 times

Last Updated: Jan 08, 2011 at 10:11 AM