Start() private method

private Start ( ) : void
return void
    // Start is called before the first frame update
    void Start()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        if (SceneManager.GetActiveScene().name == "RiverLevel")
        {
            currentState = new RiverState(this);
        }

        else if (SceneManager.GetActiveScene().name == "ForestLevel")
        {
            currentState = new ForestState(this);
        }
        else
        {
            this.gameObject.SetActive(false);
        }

        if (currentState != null)
        {
            currentState.Start();
        }
    }
    public void SwitchState(int stateID)
    {
        currentState.Stop();

        currentState = states[stateID];
        currentState.Start();
    }
Ejemplo n.º 3
0
    void Start()
    {
        currentState.Start();
        Vector3 startLook = cameraPivot.transform.rotation.eulerAngles;

        lookX = startLook.x;
        lookY = startLook.y;
    }
Ejemplo n.º 4
0
 public void ChangeState(PlayerStates state)
 {
     if (_state != null)
     {
         _state.Dispose();
         _state = null;
     }
     Debug.Log("Changing to player state : " + state.ToString());
     _state = _stateFactory.CreateState(state);
     _state.Start();
 }
Ejemplo n.º 5
0
    public void ChangeState(PlayerStates state)
    {
        if (_state != null)
        {
            _state.Dispose();
            _state = null;
        }

        _state = _stateFactory.CreateState(state);
        _state.Start();
    }
Ejemplo n.º 6
0
    void Update()
    {
        PlayerState nextState = currentState.Update();

        if (nextState != currentState)
        {
            currentState.Finish();
            currentState = nextState;
            nextState.Start();
        }
        correctCameraRotation();
    }
    private void Start()
    {
        // setup player state object
        playerStats = GetComponent<PlayerStats>();
        PlayerState.SetPlayerStats(playerStats);
        PlayerState.SetPlayerStateManager(this);

        states = new PlayerState[]
        {
          new PlayerRidingState(0),
          new PlayerCrouchState(1),
          new PlayerAirState(2),
          new PlayerFallingState(3)
        };
        Debug.Log("Initialize PlayerStateManager, riding ID: " + PlayerRidingState.ID);

        playerController = new PlayerController();

        // set initial state
        currentState = states[PlayerRidingState.ID];
        currentState.Start();
    }
Ejemplo n.º 8
0
 // Start is called before the first frame update
 public void Start()
 {
     playerState.Start();
 }
Ejemplo n.º 9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // We use a spherecast, which is like a "Fat" raytrace to see if we're hitting the ground.
        RaycastHit hit;

        //Debug.DrawRay(origin.position,new Vector3 (0, -1, 0)*1,Color.green,1f,false);
        if (Physics.SphereCast(origin.position, .5f, -transform.up, out hit, 1f))
        {
            hitNormal = hit.normal;
            onGround  = true;
        }
        else
        {
            hitNormal = new Vector3(0, 1, 0);
            onGround  = false;
        }
        if (!onGround && body.velocity.y == 0)
        {
            onGround = true;
        }

        if (newState != null)
        {
            currentState.End(this);
            currentState = newState;
            currentState.Start(this);
            newState = null;
        }
        currentState.Update(this);

        // Here's some wall-jumping logic below.
        float vert = Input.GetAxis("Vertical" + playerNum);
        float horz = Input.GetAxis("Horizontal" + playerNum);

        // We record the last time the player had the stick in neutral,
        // so that it's easier to record a joystick flick.
        if (vert + horz == 0)
        {
            lastTimeInNeutral = Time.time;
        }
        // Checking if the stick is now fully flicked, and the last time we were in neutral was less than 1/6th of a second ago, we're not currently in a walljump failure state, and we are in mid-air...
        if (((Mathf.Abs(vert) >= 0.8f || Mathf.Abs(horz) >= 0.8f) && Time.time - lastTimeInNeutral < 7f / 60f) && failWallJumpTimer <= 0 && currentState.GetType() == typeof(PlayerAirborne))
        {
            // We record the walljump direction, after converting the vector into camera space coordinates
            wallJumpDirection = camera.transform.forward * vert + camera.transform.right * horz;
            // This is how long the game will check for a wall jump
            wallJumping = 20f / 60f;
            // This is the wall jump cooldown, after failing a walljump.
            failWallJumpTimer = 20f / 60f;
        }
        if (wallJumping > 0)
        {
            wallJumping -= Time.deltaTime;
        }
        else if (failWallJumpTimer > 0)
        {
            failWallJumpTimer -= Time.deltaTime;
        }

        // Since the physics simulation doesn't like us setting velocity directly, we
        // separately keep track of our actual velocity ourselves.
        currSpeed    = (transform.position - lastPosition) / Time.deltaTime;
        lastPosition = transform.position;

        //Drive basic animations using the player's horizontal speed.
        animator.SetFloat("runSpeed", (Mathf.Abs(currSpeed.x) + Math.Abs(currSpeed.z) + 0.1f) * 0.1f);
    }