- Home /
Question by
Orloffyeah · Jul 11, 2013 at 10:19 PM ·
instantiatechildinstance
How Can I Make an Instantiated Object a Child of Other Object?
Hi, what is happening is that the code that I'm using is supposed to make a transform the child of other object, but it is giving me this error an I don't know what is wrong, can someone say me how to fix this error?
Error: "error CS1061: Type 'UnityEngine.Object' does not contain a definition for 'transform' and no extension method 'transform' of type 'UnityEngine.Object' could be found (are you missing a using directive or an assembly reference?)"
Script:
using UnityEngine;
using System.Collections;
public class Choose_Helmet : MonoBehaviour {
public GUIText hName;
public string helmetName;
public GameObject helmPrefab;
public GameObject helmSpawn;
void Start()
{
hName.enabled = false;
}
void OnMouseDown()
{
hName.enabled = true;
hName.text = (helmetName);
var helm = Instantiate(helmPrefab, helmSpawn.transform.position, Quaternion.identity);
helm.transform.parent = GameObject.Find("Runner").transform;
}
}
Comment
Best Answer
Answer by paulaceccon · Jul 11, 2013 at 10:35 PM
void OnMouseDown()
{
hName.enabled = true;
hName.text = (helmetName);
GameObject helm = Instantiate(helmPrefab, helmSpawn.transform.position, Quaternion.identity) as GameObject;
helm.transform.parent = GameObject.Find("Runner").transform;
}