- Home /
Question by
FearMePanda · Jun 18, 2012 at 01:29 PM ·
c#instantiate
Instantiate does not exist in current context.
Hey there,
I'm trying to get this bit of code to work butI cannot seem to get the instantiate to work for me.
Any thoughts?
using UnityEngine;
using System.Collections;
public class UnitManager : MonoBehaviour {
public GameObject GObject;
void Start ()
{
Unit.Create(GObject, Vector3.zero, Quaternion.identity, 0);
}
}
public class Unit
{
public static GameObject[] Units = new GameObject[50];
public static GameObject newUnit;
public static void Create(GameObject Builds, Vector3 positie, Quaternion rotatie, int ID)
{
//1. Instantiate does not exist in current context.
GameObject newUnit = Instantiate(Builds, positie, rotatie) as GameObject;
//2. error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)
GameObject newUnit = GameObject.Instantiate(Builds, positie, rotatie);
Units[ID] = newUnit;
}
}
//1. and //2. are the two different ways I tried to get it to work but neither are working out for me.
Comment
Answer by whydoidoit · Jun 18, 2012 at 01:47 PM
GameObject newUnit = GameObject.Instantiate(Builds, positie, rotatie) as GameObject;
thanks it works. :s
somehow now I feel like an idiot for not trying that out. :s
Your answer

Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Spawning a prefab at another object's location 3 Answers