How to use same code at multiple scenes ?

For example I’m gonna make a choice at “Choice.js”

public static var playerInt : int; 
    
    var playTypeString : String;
    
    function Start()
    {
    playerInt = 0;
    }
    
    function Update () {
    
    
    
    if(playerInt == 0) {
    playTypeString = "sphere";
    } else if(playerInt == 1) {
    playTypeString = "stick";
    } else if(playerInt == 2) {
    playTypeString = "plus";
    }
     
    var text = gameObject.GetComponent(TextMesh);
    text.text = playTypeString.ToString();
    }

At there I’ve set public static variable. I want to get it’s value at Game Scene and i use this;

function Start () {


if(Choice.playerInt == "0" ){

Debug.Log("player1");

}

if(Choice.playerInt == "1" ){

Debug.Log("player2");

}

}

But didn’t work.

Use DontDestroyOnLoad to mark the object not to be destroyed between scene loads, you’re using a static var in that Choice script, should be good to go. Just add the DontDestroyOnLoad to the Awake function and reference the current object.

Note: Also be aware of the order your scripts execute.