GameObject "not defined" when I try to reference across scripts
For a summary with what I'm trying to do, I'm testing a function that will allow me to switch between third person and first person when I transition to an aiming state. I thought it would be easy because all you really need to do is give it a reference, but then I realized that the aiming state script can't refer directly to unity and needs to pull reference from my main script, otherwise I would get a Null error. Here are my scripts right now:
The reference on my Character Controller Script:
[Header("Game Objects")]
public GameObject Player;
public GameObject fpsCam;
private void Start()
{
TransitionToState(idleState);
}
The function on my aiming state script:
public override void EnterState(Player_Controller player)
{
GameObject fpsCam = GameObject.FindGameObjectWithTag("fpsCam");
fpsCam.SetActive(true);
}
I figured by now it'd have a point of reference since the gameObject itself is linked to the camera in unity. But when I try to enter the aiming state it tells me that fpsCam is not defined. What am I missing here?
Your answer
Follow this Question
Related Questions
Advance Colision Detection 1 Answer
how to make an object change size automatically when playing so it doesnt go through objects 0 Answers
Null reference exception 0 Answers
Player suddenly not registered by anything? 0 Answers
How can i stop the stretch effect of a material when i add it to an object and then resize it 2 Answers