using UnityEngine;
using System.Collections;
public class SphereObj : MonoBehaviour {
private GameObject manager;
void Awake () {
//things
}
public void SetParent(GameObject myManager) {
manager = myManager;
}
}
test
using UnityEngine;
using System.Collections;
public class SphereManager : MonoBehaviour {
int position;
int detail;
public GameObject preSphere;
void Start () {
for(int i = 0; i < detail; i++){
SphereObj itsMe = Instantiate(preSphere, new Vector3(0, 0, 0), Quaternion.identity) as SphereObj;
itsMe.SetParent(gameObject);
}
}
}
So im building a game with basicly an unlimited amout of spheres and im instantiating all from a prefab. the prefabs got the first script attached managing sphere stuff, but i want them to have access to variables from the manager script, which is linked to an empty gameobject spawning things. my plan was to link the manager to the sphere scripts by this function:
itsMe.SetParent(gameObject);
but im geting this error
NullReferenceException: Object reference not set to an instance of an object
refering to the line mentioned above.
please help
thanks ahead.
gameObject
\$\endgroup\$