Hi,
I was wondering if someone can tell me why I am getting this error. I am trying to find the child object called ‘sectionend’ of a prefab in the scene, and them Instantiate section2_prefab from this point. The object ‘section1_prefab1’ is definitely in the scene with its child object ‘sectionend’;
using UnityEngine;
using System.Collections;
public class TrackAssemb : MonoBehaviour {
// Use this for initialization
void Awake()
{
section1 = Resources.Load("Level_prototype_V1/section1_prefab", typeof(Transform)) as Transform;
section2 = Resources.Load("Level_prototype_V1/section2_prefab", typeof(Transform)) as Transform;
section3 = Resources.Load("Level_prototype_V1/section3_prefab", typeof(Transform)) as Transform;
section4 = Resources.Load("Level_prototype_V1/section4_prefab", typeof(Transform)) as Transform;
section5 = Resources.Load("Level_prototype_V1/section5_prefab", typeof(Transform)) as Transform;
}
GameObject endPoint;
bool flag = false;
// Update is called once per frame
void Update ()
{
if(flag == false)
{
// Find the position of the end point of the current section
endPoint = GameObject.Find("section1_prefab1/sectionend");
//gameObject.transform.position = endPoint.transform.position;
//---Section 2
// Create an instance of a section joining onto the end point found.
Transform Instance = Instantiate(section2, endPoint.transform.position, endPoint.transform.rotation) as Transform;
flag = true;
}
}