I am creating instance ofmy prefab and i need to set variable in his script but i tried many solution and this is not working. Its my code.
I tried:
- GameObject.Find(“name”).GetComponent()
- camera.GetComponent.().someVariable = someNumber;
- ScriptName script = (ScriptName) Camera.main.GetComponent(“ScriptName”);
and nothing… Now my code looks like this :
code of instantinated prefab:
public class Camera_Move : MonoBehaviour {
public int test;
}
code of Level Loader:
public class Level_Generator : MonoBehaviour
{
public GameObject camera1;
public Camera_Move camera_script;
void Start () {
camera1 = Instantiate(camera1, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;
camera_script = camera1.GetComponent(typeof(Camera_Move)) as Camera_Move;
camera_script.test = 100;
}