Issues switching between controller scripts,Attempting to switch between Controller Scripts for Player and Cannon. Having Issue accessing both scripts to enable and disable.
I want my character(Using standard assets FPS Controller) to walk up to a cannon press "L" and be able to rotate and aim the cannon (and eventually fire). I am trying to use two different controller scripts and enable/disable them on press of L. I am also switching between cameras. The camera script works and I am basing this script off of the camera switch script. So, I have created an game object titled "gameflow" to handle the controllers switching. However I am having trouble accessing the controller scripts in both the Cannon and player objects to be able to do this. Below is my GameFlow Script please tell me if there is a better method, or if I am writing this incorrectly and how to fix it. Thank you. P.S. I am new to Unity and GameDev.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameFlow : MonoBehaviour
{
public GameObject cannon;
public GameObject player;
// Start is called before the first frame update
void Start()
{
cannon.GetComponent<CannonControl>() = false;
player.GetComponent<FirstPersonController>() = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
//Check that Can Con is enabled in the scene, then switch cams on L
if (cannon.GetComponent<CannonControl>().enabled = true)
{
//Enables Can Con
cannon.GetComponent<CannonControl>().enabled = true;
//Disables Player Con
player.GetComponent<FirstPersonController>().enabled = false;
}
//otherwise if the CanCon is not enabled
else if (cannon.GetComponent<CannonControl>().enabled = false)
{
//Disables Cannon Controller
cannon.GetComponent<CannonControl>().enabled = false;
//Enables Player Controller
player.GetComponent<FirstPersonController>().enabled = true;
}
}
}