Well, I’m making a game where its different game types all in one. Its a massive team project for school and I am the only programmer,I literally learned Java in 5 weeks by myself scrounging through here However, I cant get my code to work properly. In the picture provided, I have two Colliders. What I want my script to do is when I press e and collied with one, it will switch me to one controller, when I collide with the other box,it will move me to the second character controller. However, when I collided with either, it just moves me to the same character controller and in addition, when I press play I can press play and my camera automatically switches. I have to move at least once before it limits the key press to the colliders. I tried seperate scripts, variables, so I tried to be as specific as I can with tags. My boolean doesnt seem to work properly, anyway to limit which collisions to specific names?
//First Collider Script
var change:boolean = false;
//var PlayerCam: GameObject;
//var NodeCam: GameObject;
//var KeyCam: GameObject;
//var NodeTrigger: GameObject;
var GameTypeTrigger: GameObject;
function OnTriggerEnter(col: Collider){
//Function onTriggerEnter(OnTriggerEnter is called when the Collider "coll" other enters the trigger and activates-
//the function update below)
change = true;
//(activate = true;) refer to the variable playerCam:boolean to be active or true) S
}
function OnTriggerExit(col:Collider){
// OnTriggerExit is called when the Collider other has stopped touching the trigger.
change = false;
//VariableCameraName.UnityCameraObject.Enabled/Disbaled = Activate
}
function Update(){
if(Input.GetKeyDown("e") && change){
Debug.Log("switch ready");
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = false;
GameObject.FindWithTag("nodeCam").camera.enabled = true;
//Enables Node Camera
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = true;
//Enables Node Control
GameObject.FindWithTag("firstPersonCharacter").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = false;
//Disables Platformer Functionality
}
}
//Second Collider Script
var activate:boolean = false;
//var PlayerCam: GameObject;
//var KeyCam: GameObject;
//var NodeCam:GameObject;
var PlatformerTrigger: GameObject;
//var GameTypeTrigger: GameObject;
function OnTriggerEnter(col: Collider){
//Function onTriggerEnter(OnTriggerEnter is called when the Collider "coll" other enters the trigger and activates-
//the function update below)
activate = true;
//(activate = true;) refer to the variable playerCam:boolean to be active or true) S
}
function OnTriggerExit(col:Collider){
// OnTriggerExit is called when the Collider other has stopped touching the trigger.
activate = false;
//VariableCameraName.UnityCameraObject.Enabled/Disbaled = Activate
}
function Update(){
if(Input.GetKeyDown("e") && activate){
Debug.Log("switch ready");
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = true;
GameObject.FindWithTag("nodeCam").camera.enabled = false;
//Enables Node Camera
GameObject.FindWithTag("firstPersonCharacter").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = false;
//Disables BombDiffusal Functionality
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = true;
//Enables Platformer Functionality
}
}
Toborific I Found a workaround thanks to your first OnTriggerEnter Solution however, I did not know you can apply a collider setting to an OnTrigger thinking it was unity preset and not modifiable . Thanks! I appreciate it!
Here is my Workaround But I will try what you provided now
function OnTriggerEnter(other: Collider) {
if(other.gameObject.tag == "nodeTrigger")
{
Debug.Log("Working!");
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = true;
//Enables Node Control
GameObject.FindWithTag("Player").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = false;
//Disables Platformer Functionality
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = false;
GameObject.FindWithTag("nodeCam").camera.enabled = true;
//Enables Node Camera
}
else if (other.gameObject.tag == "keyTrigger") {
Debug.Log("otheroneisWorking!");
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = false;
//Enables Node Control
GameObject.FindWithTag("Player").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = true;
//Disables Platformer Functionality
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = true;
GameObject.FindWithTag("nodeCam").camera.enabled = false;
//Enables Node Camera
}
}
//First Collider Script
var change:boolean = false;
//var PlayerCam: GameObject;
//var NodeCam: GameObject;
//var KeyCam: GameObject;
//var NodeTrigger: GameObject;
var GameTypeTrigger: GameObject;
function OnTriggerEnter(col: Collider){
//Function onTriggerEnter(OnTriggerEnter is called when the Collider "coll" other enters the trigger and activates-
//the function update below)
if(col.tag == "YOURTAG")
{
change = true;
}
//(activate = true;) refer to the variable playerCam:boolean to be active or true) S
}
function OnTriggerExit(col:Collider){
// OnTriggerExit is called when the Collider other has stopped touching the trigger.
if(col.tag == "YOURTAG")
{
change = false;
}
//VariableCameraName.UnityCameraObject.Enabled/Disbaled = Activate
}
function Update(){
if(Input.GetKeyDown("e") && change == true){
Debug.Log("switch ready");
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = false;
GameObject.FindWithTag("nodeCam").camera.enabled = true;
//Enables Node Camera
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = true;
//Enables Node Control
GameObject.FindWithTag("firstPersonCharacter").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = false;
//Disables Platformer Functionality
}
}
//Second Collider Script
var activate:boolean = false;
//var PlayerCam: GameObject;
//var KeyCam: GameObject;
//var NodeCam:GameObject;
var PlatformerTrigger: GameObject;
//var GameTypeTrigger: GameObject;
function OnTriggerEnter(col: Collider){
//Function onTriggerEnter(OnTriggerEnter is called when the Collider "coll" other enters the trigger and activates-
//the function update below)
if(col.tag == "YOURTAG")
{
activate = true;
}
//(activate = true;) refer to the variable playerCam:boolean to be active or true) S
}
function OnTriggerExit(col:Collider){
// OnTriggerExit is called when the Collider other has stopped touching the trigger.
if(col.tag == "YOURTAG")
{
activate = false;
}
//VariableCameraName.UnityCameraObject.Enabled/Disbaled = Activate
}
function Update(){
if(Input.GetKeyDown("e") && activate == false){
Debug.Log("switch ready");
GameObject.FindWithTag("playerCam").camera.enabled = false;
//Disables FirstPerson Camera
GameObject.FindWithTag("keyCam").camera.enabled = true;
GameObject.FindWithTag("nodeCam").camera.enabled = false;
//Enables Node Camera
GameObject.FindWithTag("firstPersonCharacter").GetComponent("FPSInputController").enabled = false;
//Disables FirstPerson Control
GameObject.FindWithTag("nodeCharacter").GetComponent("TopDownController").enabled = false;
//Disables BombDiffusal Functionality
GameObject.FindWithTag("keyCharacter").GetComponent("CharacterController").enabled = true;
//Enables Platformer Functionality
}
}