I am trying to get this script to work with a UI button

#pragma strict

var cam01 : GameObject; // first person camera
var cam02 : GameObject; // third person camera
var player01 : GameObject; //first person controller
var player02 : GameObject; //third person controller
var check; // New check-variable

//start with first person active
function Start() {
cam01.gameObject.active = true;
cam02.gameObject.active = false;
player02.active = false;
check = true;

}

function Update() {

//player01.transform.position = player02.transform.position;

if (Input.GetButtonDown ("CharSwitch")) {
    if(check) {
        cam01.gameObject.active = false; 
        cam02.gameObject.active = true; 
        player01.active = false;
        player02.active = true;
        
    }
    else {
        cam01.gameObject.active = true; 
        cam02.gameObject.active = false; 
        player01.active = true;
        player02.active = false;
       
    }
    check = !check;
    player02.transform.position = player01.transform.position;
}

}

Create a function instead of input like void OnClick(){}, then if you select the button in inspector, it will have an OnClick function in the Button(Script) component, click on the plus then drag your object into the box, select its attached script and the OnClick function in it.