- Home /
 
               Question by 
               Karthikeyan_Ajax · Nov 27, 2015 at 10:10 AM · 
                variablesgameobjectsprefab-instancestrings  
              
 
              Accesing variable from another class for instantiated gameobjects
using UnityEngine; using System.Collections;
public class Script_1 : MonoBehaviour {
 public GameObject one;
 private GameObject[] ones;
 private float timer;
 int count;
 public string names;
 // Use this for initialization
 void Start () {
     names = "NEED ANSWER";
 }
 
 // Update is called once per frame
 void Update () {
     timer += Time.deltaTime;
     if (timer > 4) {
         timer = 0;
         ones[count] = Instantiate(one)as GameObject;
         count++;
     }
 }
}
using UnityEngine; using System.Collections;
public class script_2 : MonoBehaviour {
 public GameObject script1;
 private Script_1 scriptControl;
 // Use this for initialization
 void Start () {
     scriptControl = script1.GetComponent<Script_1> ();
 }
 
 // Update is called once per frame
 void Update () {
     print (scriptControl.names);
 }
}
when the gameobject creates it showing error message object reference is not set to an instance of a object so please kindly help me out in this . how to access the variable string from script_1 to all the instantiated prefabs..
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                