How would I Trigger a Change in Inputs

I have 2 scripts attached to my Player.

Here:

(SSController)

public var cont1 : int;
private var motor : CharacterMotor;

// Use this for initialization
function Awake () {
	motor = GetComponent(CharacterMotor);
}

// Update is called once per frame

function Update () {
	
	if (cont1 == 1){
	// Get the input vector from kayboard or analog stick
	var directionVector = new Vector3(Input.GetAxis("SSVertical"), 0, Input.GetAxis("SSHorizontal"));
	
	if (directionVector != Vector3.zero) {
		// Get the length of the directon vector and then normalize it
		// Dividing by the length is cheaper than normalizing when we already have the length anyway
		var directionLength = directionVector.magnitude;
		directionVector = directionVector / directionLength;
		
		// Make sure the length is no bigger than 1
		directionLength = Mathf.Min(1, directionLength);
		
		// Make the input vector more sensitive towards the extremes and less sensitive in the middle
		// This makes it easier to control slow speeds when using analog sticks
		directionLength = directionLength * directionLength;
		
		// Multiply the normalized direction vector by the modified length
		directionVector = directionVector * directionLength;
		}
	}
	// Apply the direction to the CharacterMotor
	motor.inputMoveDirection = transform.rotation * directionVector;
	motor.inputJump = Input.GetButton("Jump");
}

// Require a character controller to be attached to the same game object
@script RequireComponent (CharacterMotor)
@script AddComponentMenu ("Character/FPS Input Controller")

(SSControler2)

public var cont1 : int;
private var motor : CharacterMotor;

// Use this for initialization
function Awake () {
	motor = GetComponent(CharacterMotor);
}

// Update is called once per frame

function Update () {
	
	if (cont1 == 2){
	// Get the input vector from kayboard or analog stick
	var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));
	
	if (directionVector != Vector3.zero) {
		// Get the length of the directon vector and then normalize it
		// Dividing by the length is cheaper than normalizing when we already have the length anyway
		var directionLength = directionVector.magnitude;
		directionVector = directionVector / directionLength;
		
		// Make sure the length is no bigger than 1
		directionLength = Mathf.Min(1, directionLength);
		
		// Make the input vector more sensitive towards the extremes and less sensitive in the middle
		// This makes it easier to control slow speeds when using analog sticks
		directionLength = directionLength * directionLength;
		
		// Multiply the normalized direction vector by the modified length
		directionVector = directionVector * directionLength;
		}
	}
	// Apply the direction to the CharacterMotor
	motor.inputMoveDirection = transform.rotation * directionVector;
	motor.inputJump = Input.GetButton("Jump");
}

// Require a character controller to be attached to the same game object
@script RequireComponent (CharacterMotor)
@script AddComponentMenu ("Character/FPS Input Controller")

and another script attached to a trigger that changes the int on each script accordingly.

The int changes on the scripts like it’s supposed to… But for some reason when Cont1 becomes 2

I loose all movement. . where my SSController2 script should begin it doesnt seem to want to work???

Whats going on?

Hello,
Well you don’t need two scripts for that, one simple alteration that you can do is this:

(SSController)

public var cont1 : int;
private var motor : CharacterMotor;

// Use this for initialization
function Awake () {
    motor = GetComponent(CharacterMotor);
}

// Update is called once per frame

function Update () {

    if (cont1 == 1){
    // Get the input vector from kayboard or analog stick
    var directionVector = new Vector3(Input.GetAxis("SSVertical"), 0, Input.GetAxis("SSHorizontal"));

    if (directionVector != Vector3.zero) {
       // Get the length of the directon vector and then normalize it
       // Dividing by the length is cheaper than normalizing when we already have the length anyway
       var directionLength = directionVector.magnitude;
       directionVector = directionVector / directionLength;

       // Make sure the length is no bigger than 1
       directionLength = Mathf.Min(1, directionLength);

       // Make the input vector more sensitive towards the extremes and less sensitive in the middle
       // This makes it easier to control slow speeds when using analog sticks
       directionLength = directionLength * directionLength;

       // Multiply the normalized direction vector by the modified length
       directionVector = directionVector * directionLength;
       }
    }else if(cont1 == 2){
    // Get the input vector from kayboard or analog stick
    var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));

    if (directionVector != Vector3.zero) {
       // Get the length of the directon vector and then normalize it
       // Dividing by the length is cheaper than normalizing when we already have the length anyway
       var directionLength = directionVector.magnitude;
       directionVector = directionVector / directionLength;

       // Make sure the length is no bigger than 1
       directionLength = Mathf.Min(1, directionLength);

       // Make the input vector more sensitive towards the extremes and less sensitive in the middle
       // This makes it easier to control slow speeds when using analog sticks
       directionLength = directionLength * directionLength;

       // Multiply the normalized direction vector by the modified length
       directionVector = directionVector * directionLength;
       }
}
    // Apply the direction to the CharacterMotor
    motor.inputMoveDirection = transform.rotation * directionVector;
    motor.inputJump = Input.GetButton("Jump");
}

// Require a character controller to be attached to the same game object
@script RequireComponent (CharacterMotor)
@script AddComponentMenu ("Character/FPS Input Controller")

Well, see if that works for you. This way changing the variable at the first script will make the same script do your second script functions.

If this doesn’t work try to see if your configurations on SSHorizontal2 and SSVertical2 axis are OK.
If your intention is to invert the inputs when you enter the trigger, you could try and use this:

var directionVector = new Vector3(Input.GetAxis("SSHorizontal"), 0, Input.GetAxis("SSVertical"));

instead of this:

 var directionVector = new Vector3(Input.GetAxis("SSHorizontal2"), 0, Input.GetAxis("SSVertical2"));

After your else if. If that isn’t what you want, please ignore. Take care.

If I understand correctly, you want to switch between these 2 controller scripts, one active at a time, right?

First, using cont1 in both scripts does not make them both use the same variable. You would need one of them to be a static, and the other would not exist (other script would access the static var) or you would need to get the instance of that other component and get cont1 on it.

The way I’ve done this is have 3rd script with knows about the other 2 and just sets the ‘enabled’ flag on them accordingly