Lost??????

I am trying to go from thridperson to FirstPerson threw another script but i dont know wha i am doing wrong

I have try’d gameObject.GetComponent<HeroCamera.CameraState.Firstperon> ().enabled =true
and a few others but it’s not working?

ok, few problems…

components are the things you add that show up in the inspector of a gameobject, so scripts, rigidbodies, renderers etc.

within components there are variables and functions, in order to get access to those you need a reference to the component. Reference first, variable/function second :slight_smile:

in that script the camerastate is governed by a single variable called “camState” which pulls from an enum “CameraState”, then around line150 there is a switch which checks that variable and does the appropriate thing.

so:

// get reference to the herocamera on this gameobject
HeroCamera hc = GetComponent<HeroCamera>();
// change the variable to a different option from the enum "CameraState"
hc.camState = CameraState.FirstPerson;

scripts are case sensitive so “Firstperson” (ignoring the typo) isn’t going to work.

https://unity3d.com/learn/tutorials/modules/beginner/scripting/scripts-as-behaviour-components?playlist=17117
https://unity3d.com/learn/tutorials/topics/scripting/variables-and-functions?playlist=17117
https://unity3d.com/learn/tutorials/topics/scripting/enumerations

https://unity3d.com/learn/tutorials/topics/scripting :slight_smile:

1 Like

thx