Search Unity

Lost??????

Discussion in 'Scripting' started by keepthachange, Aug 3, 2016.

  1. keepthachange

    keepthachange

    Joined:
    Oct 15, 2014
    Posts:
    87
    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?
     
    Last edited: Aug 3, 2016
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    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 :)

    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:

    Code (csharp):
    1.  
    2. // get reference to the herocamera on this gameobject
    3. HeroCamera hc = GetComponent<HeroCamera>();
    4. // change the variable to a different option from the enum "CameraState"
    5. hc.camState = CameraState.FirstPerson;
    6.  
    scripts are case sensitive so "Firstperson" (ignoring the typo) isn't going to work.

    https://unity3d.com/learn/tutorials...cripts-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 :)
     
    keepthachange likes this.
  3. keepthachange

    keepthachange

    Joined:
    Oct 15, 2014
    Posts:
    87
    thx