Access to public variable of instantinated prefab not working

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:

  1. GameObject.Find(“name”).GetComponent()
  2. camera.GetComponent.().someVariable = someNumber;
  3. 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;
       
    }

hi ;
your problem is you are trying to accesss your prefab not the instantiated object the names are same ;

do it this way :

GameObject cameraCreated = Instantiate(camera1, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;

camera_script = cameraCreated .GetComponent(typeof(Camera_Move)) as Camera_Move;
camera_script.test = 100;