Пример #1
0
    public PlayerController(InputController _input, Rigidbody _rb, GravityObject _gravObj, Animator _animator, Collider coll)
    {
        input     = _input;
        rb        = _rb;
        animator  = _animator;
        transform = rb.transform;

        //set gravobj corners
        gravObj = _gravObj;
        gravObj.SetCorners(
            new Vector3[4] {
            new Vector3(coll.bounds.extents.x - boundsAdjust, 0, 0),
            new Vector3(0, 0, coll.bounds.extents.z - boundsAdjust),
            new Vector3(-coll.bounds.extents.x + boundsAdjust, 0, 0),
            new Vector3(0, 0, -coll.bounds.extents.z + boundsAdjust)
        }
            );

        //init state machine
        Dictionary <string, State> states = new Dictionary <string, State>();

        states.Add("Grounded", new State(
                       new State.StateAction(GroundedEnter),
                       new State.StateAction(GroundedUpdate),
                       new State.StateAction(GroundedExit)
                       )
                   );
        states.Add("Jumping", new State(
                       new State.StateAction(JumpingEnter),
                       new State.StateAction(JumpingUpdate),
                       new State.StateAction(JumpingExit)
                       )
                   );
        fsm = new StateMachine(states, "Grounded");
    }
Пример #2
0
    void Start()
    {
        rb   = GetComponent <Rigidbody>();
        anim = GetComponent <Animator>();
        anim.SetFloat("Speed", speed);

        gravObj        = GetComponent <GravityObject>();
        gravObj.planet = FindObjectOfType <SceneData>().planet;
        Collider coll = GetComponent <Collider>();

        gravObj.SetCorners(
            new Vector3[4] {
            new Vector3(coll.bounds.extents.x - boundsAdjust, 0, 0),
            new Vector3(0, 0, coll.bounds.extents.z - boundsAdjust),
            new Vector3(-coll.bounds.extents.x + boundsAdjust, 0, 0),
            new Vector3(0, 0, -coll.bounds.extents.z + boundsAdjust)
        }
            );
    }