Inheritance: StateClass
Beispiel #1
0
 void DetectState(Collider2D other)
 {
     // Si el collider tiene tag Ground, reseteamos las animaciones y cambiamos el estado a Grounded.
     if (IsTagged("Ground", other) || IsTagged("Enemy", other))
     {
         ResetAnims();
         movementScript.SwapState(GroundedState.GetInstance());
     }
     // Si el collider tiene tag Rope (Soga), le avisamos al script de interaccion que tiene un objeto
     // para interactuar, y no hacemos nada más.
     else if (IsTagged("Rope", other))
     {
         interactionScript.objectToInteract = other.gameObject;
         feedbackScript.ShowRopeFeedback();
     }
     // Si el collider tiene tag Water, reseteamos las animaciones, cambiamos el estado a Swimming y
     // le avisamos al animatorController que se esta nadando.
     else if (IsTagged("Water", other))
     {
         ResetAnims();
         movementScript.SwapState(SwimmingState.GetInstance());
         movementScript.anim.SetBool("isSwimming", true);
     }
     else if (IsTagged("TeleportInteracter", other))
     {
         interactionScript.objectToInteract = other.gameObject;
         feedbackScript.ShowDoorFeedback();
     }
 }
Beispiel #2
0
    private void Start()
    {
        GetBalaIndex();

        GetRigidBody().drag = GetPlayerDeceleration();

        life  = 1;
        score = 0;
        SetCanShoot(true);
        damageable = true;

        matchController = FindObjectOfType <MatchController>();
        //matchController.AddPlayer(this);
        spawnPoint = matchController.GetSpawnPoint(this);

        teamId = 5;

        movementSM = new StateMachine();

        groundedState = new GroundedState(this, movementSM);
        shootingState = new ShootingState(this, movementSM);
        shieldState   = new ShieldState(this, movementSM);
        deadState     = new DeadState(this, movementSM);
        stunState     = new StunState(this, movementSM);
        feederState   = new FeederState(this, movementSM);

        movementSM.Initialize(shootingState);
    }
    private void Start()
    {
        state = new StateMachine();

        grounding = new GroundedState(gameObject, state);
        shooting  = new ShootingState(gameObject, state);
        state.Initialize(grounding);
    }
Beispiel #4
0
 static public GroundedState GetInstance()
 {
     if (instance == null)
     {
         instance = new GroundedState();
     }
     return(instance);
 }
 //
 private void FixedUpdate()
 {
     // Raycast down
     if (Physics.BoxCast(groundedRaycastSource.position, boxCast.size / 2, Vector3.down, out _downRayHit, transform.rotation, groundedDistance, groundLayers))
     {
         if (groundedState != GroundedState.Grounded && _playerMotor.GetplayerMovementVector().y < 0 && !_detectorCollider._isCollided)
         {
             OnLand();
         }
     }
     else
     {
         groundedState = GroundedState.Airborne;
     }
 }
    private void InitializeAirMachine()
    {
        AerialState      s_aerial      = new AerialState(ref c_playerData, ref c_collisionData, ref c_aerialMoveData, ref c_positionData);
        GroundedState    s_grounded    = new GroundedState(ref c_playerData, ref c_aerialMoveData, ref c_collisionData, ref c_positionData);
        BoostState       s_boost       = new BoostState(ref c_playerData, ref c_aerialMoveData, ref c_collisionData, ref c_positionData, ref c_turnData);
        JumpChargeState  s_jumpCharge  = new JumpChargeState(ref c_playerData, ref c_positionData, ref c_collisionData, ref c_aerialMoveData, ref cart_incr);
        AirDisabledState s_airDisabled = new AirDisabledState();

        c_airMachine = new StateMachine(StateRef.GROUNDED);
        c_airMachine.AddState(s_grounded, StateRef.GROUNDED);
        c_airMachine.AddState(s_aerial, StateRef.AIRBORNE);
        c_airMachine.AddState(s_jumpCharge, StateRef.CHARGING);
        c_airMachine.AddState(s_airDisabled, StateRef.DISABLED);
        c_airMachine.AddState(s_boost, StateRef.GROUNDED_BOOSTING);
    }
Beispiel #7
0
    //Here for the Object Pooling
    public void InitializeVariables()
    {
        var componentAnimator  = GetComponent <Animator>();
        var componentCollider  = GetComponent <Collider>();
        var componentRigidBody = GetComponent <Rigidbody>();

        _movementState = new StateMachine();
        _actionState   = new StateMachine();

        _idle     = new IdleState(componentAnimator, IdleAnimation);
        _grounded = new GroundedState();
        _airborn  = new AirbornState(componentCollider, componentRigidBody, 0, AirbornCallback);
        _death    = new DeathState(componentAnimator, ExplosionAnimation, componentCollider, DeathCallback, PostMortermResult);

        _actionState.ChangeState(_idle);
        _movementState.ChangeState(_grounded);
    }
Beispiel #8
0
    internal override void Awake()
    {
        base.Awake();
        var playerAnimator  = GetComponent <Animator>();
        var playerRigidBody = GetComponent <Rigidbody>();
        var playerCollider  = GetComponent <Collider>();

        Punch = new PunchState(playerAnimator, actorAnimations.ActorAttacking,
                               DonePunching);
        Idle     = new IdleState(playerAnimator, actorAnimations.ActorIdle);
        Grounded = new GroundedState();
        Jump     = new JumpState(playerCollider,
                                 playerRigidBody, JumpSpeed, EvalJumpData);
        DiveKick  = new DiveKickState(playerRigidBody, 20f, ActorLookingRight);
        Knockback = new KnockbackState(playerCollider, 5f, ActorLookingRight, EvalKnockbackResult);
        actionState.ChangeState(Idle);
        movementState.ChangeState(Grounded);
    }
Beispiel #9
0
    private void Start()
    {
        rigidBody.drag = playerDeceleration;

        life                = maxLife;
        score               = 0;
        canShoot            = true;
        canShield           = true;
        damageable          = true;
        stunSlider.maxValue = stunTime;

        lifeText.text = "Vida: " + life;
        scoreText.GetComponent <TMPro.TextMeshProUGUI>().text = score + " pts";
        hudManager = GetComponent <HUDmanager>();
        GetBalaIndex();
        if (PhotonNetwork.IsConnected && PV.IsMine)
        {
            canvas.SetActive(true);
            mainCamera.enabled      = true;
            playerInput.enabled     = true;
            mobileCharacter.enabled = true;
            audioListener.enabled   = true;
            sAlas.Play();
        }
        if (PhotonNetwork.IsConnected && PhotonNetwork.IsMasterClient)
        {
            matchController = FindObjectOfType <MatchController>();
            matchController.AddPlayer(this);
            teamId = FindObjectOfType <RoomManager>().FindTeamIdByPlayer(PV.Owner);
            if (teamId == -1)
            {
                teamId = 0;
                Debug.Log("No se ha encontrado el teamId, se le ha añadido al equipo 0");
            }
            PV.RPC("GetSpawnpoint_RPC", RpcTarget.All, teamId);
        }
        else if (!PhotonNetwork.IsConnected)
        {
            canvas.SetActive(true);
            mainCamera.enabled      = true;
            playerInput.enabled     = true;
            mobileCharacter.enabled = true;
            RoomManagerOffline RMO = FindObjectOfType <RoomManagerOffline>();
            if (RMO.gamemodeIndex == 3)
            {
                teamId = 0;
            }
            else
            {
                teamId = RMO.jugadoresInfo[GetComponentInChildren <PlayerInput>().playerIndex + 1][1];
            }
            if (playerInput.playerIndex == 0)
            {
                audioListener.enabled = true;
            }
            matchController = FindObjectOfType <MatchController>();
            matchController.AddPlayer(this);
            spawnPoint = matchController.GetSpawnPoint(this);
            GetComponent <Transform>().position = spawnPoint.transform.position;
            hudManager.setBackground();
        }

        movementSM = new StateMachine();

        groundedState = new GroundedState(this, movementSM);
        shootingState = new ShootingState(this, movementSM);
        shieldState   = new ShieldState(this, movementSM);
        deadState     = new DeadState(this, movementSM);
        stunState     = new StunState(this, movementSM);
        feederState   = new FeederState(this, movementSM);

        movementSM.Initialize(groundedState);
    }
 //
 private void OnLand()
 {
     groundedState = GroundedState.Grounded;
     _playerMotor.OnGrounded();
     Debug.Log("G R O U N D E D");
 }