Activating/deactivating Cameras

Hi,
I have a Camera with two different scripts for a different follow mode each (3rd person view and a Sidescroller view)
I want to be able to change (activate the second script/deactivate the primary and vice-versa) via a OnCollider script attached to meshes.
Has my camera is named “MainCamera” (also tagged MainCamera)

I want my script “Follow on X” to be activated by default and the script “SmoothFollow” to be the second one.
I am missing some pieces of the puzzle, there`s what I have so far :

var camera: Camera;
var camside: Follow on X = gameObject.GetComponent("Follow on X") ;
var cam3rd: SmoothFollow = gameObject.GetComponent("SmoothFollow");

function OnControllerColliderHit(hit:ControllerColliderHit){

    if(hit.gameObject.tag=="CamButtonSideTo3rd"){
    
        GetComponent("Follow on X");
        Follow on X.enabled=false;
        
        GetComponent("SmoothFollow");
        SmoothFollow.enabled=true;
        
    }
    
    if(hit.gameObject.tag=="CamButton3rdToSide"){
    
    GetComponent("Follow on X");
    Follow on X.enabled=true;
        
    GetComponent("SmoothFollow");
    SmoothFollow.enabled=false;
    
    }
    
}

I am surely totaly wrong, I did my best with what I saw on the documentation stuff…
If anyone could put me in the right way =/

Thanks !

use else:

var camera: Camera; 
var camside: Follow on X = gameObject.GetComponent("Follow on X") ; 
var cam3rd: SmoothFollow = gameObject.GetComponent("SmoothFollow"); 

function OnControllerColliderHit(hit:ControllerColliderHit){ 

    if(hit.gameObject.tag=="CamButtonSideTo3rd"){ 
    
        GetComponent("Follow on X"); 
        Follow on X.enabled=false; 
        
        GetComponent("SmoothFollow"); 
        SmoothFollow.enabled=true; 
        
    } 
    
    else if(hit.gameObject.tag=="CamButton3rdToSide"){ 
    
    GetComponent("Follow on X"); 
    Follow on X.enabled=true; 
        
    GetComponent("SmoothFollow"); 
    SmoothFollow.enabled=false; 
    
    } 
    
}

After some more work/research, I saw I was having some error saying missing “;” to all my line with Follow on X, etc…
I cant declare a variable with space >.>
So I changed the name, the errors were gone, but I had this : “You are not allowed to call this function while declaring a variable, move it to the next line…”

So I changed all to this

I still get
Assets/MySCRIPTS/ChangeCam.js(2,27): BCE0022: Cannot convert ‘boolean’ to ‘UnityEngine.GameObject’.
[same for (3,26)]

Assets/MySCRIPTS/ChangeCam.js(14,25): BCE0019: ‘enabled’ is not a member of ‘UnityEngine.GameObject’.
[same for (17,24), (27,16), (30,16)]

I think I dont enable/disable attached Script with this…
Anyone could point me to the good stuff "?

Tkx

You should look into MonoBehaviour and enable
I use an array to add more scripts later if needed.

var scriptOnToggle : MonoBehaviour[];

function Update() {
  //if statment  {
  for(var s in scriptOnToggle)
  s.enabled = false;
  }
}

Sorry i was to lazy to write the if statment lol. :smile:

Thanks ! This seems to go well, still, here’s the deal now :

var scriptOnToggle : MonoBehaviour[];


function OnControllerColliderHit(hit:ControllerColliderHit){

    if(hit.gameObject.tag=="CamButtonSideTo3rd"){
    
        for(var s in scriptOnToggle)
        
            s.enabled = true;
        
        for(var t in scriptOnToggle)
        
            t.enabled = false;
        
  } else if(hit.gameObject.tag=="CamButton3rdToSide"){
  
        for(var s in scriptOnToggle)
        
            s.enabled = false;
            
        for(var t in scriptOnToggle)
        
            t.enabled = true;
  
  }
  
}

I increased the size to 2 element, cause I want to be able to switch on/off two of my script (the 2 different view script) attached to my camera. And when I import my camera in the 2 slots, by default I get one of the two (“Follow onX”)
but I cant change the second one… the arrow next to it give me nothing in the drop down menu.
Maybe its because the object this script is on, is not in my scene, its on objects that are instantiate with a GameStarter script. So I must import from prefabs (witch I did for my MainCamera).
So how can I get my second component good ?
Can I manually call them in the script ? (Second name’s “SmoothFollow”)
Also, I’ve never work with a scriptOnToggle, how will the script link var “s” and “t” with my element, how must I name them right ?

Thanks for the help people, its really appreciate !

Destroyed the instantiate thing and putted the mesh directly into the scene, so now I can import all my scripts from the camera. :slight_smile:

Still, I dont know how to declare my varibles
“For s in scriptOnToggle…”

Is it :

var s=GameObject(“???”);

?
My Element 0 is "MainCamera (Follow on X)
Element 1 is "MainCamera (SmoothFollow)

Thks

Here an update on my code

var scriptOnToggle : MonoBehaviour[];

function OnControllerColliderHit(hit:ControllerColliderHit){

    if(hit.gameObject.tag=="CamSideTo3rd"){
    
    
        for(var Element0 in scriptOnToggle)
        
            Element0.enabled = true;
        
        for(var Element1 in scriptOnToggle)
        
            Element1.enabled = false;
        
  } else if(hit.gameObject.tag=="Cam3rdToSide"){
  
        for(var Element0 in scriptOnToggle)
        
            Element0.enabled = false;
            
        for(var Element1 in scriptOnToggle)
        
            Element1.enabled = true;
  
  }
  
}