コード例 #1
0
ファイル: UnitHealth.cs プロジェクト: solkar/GGJ19
    public void TakeDamage(float damage)
    {
        health -= damage;

        if (health < 0)
        {
            stateMachine.RequestChangePlayerState(CharacterStateMachine.CharacterState.dead);
            StartCoroutine(RemoveUnit());
            Debug.Log("Dead!!");
        }

        OnDamage?.Invoke(damage);
    }
コード例 #2
0
            public IEnumerator Enter()
            {
                done = false;

                animatorFSM.RequestChangePlayerState(CharacterStateMachine.CharacterState.attacking);

                yield return(new WaitForSeconds(settings.timeBetweenAttacks));

                if (Hit.HitCheck(target, agent.transform, settings.attackDistance, settings.attackRange))
                {
                    target.GetComponent <PlayerController>()?.TakeDamage(1);
                    Debug.Log("Damageeee!!!");
                }

                done = true;
            }
コード例 #3
0
    void Update()
    {
        var fireButton1 = Input.GetAxisRaw("Fire1") != 0 || Input.GetKeyDown(KeyCode.Space);
        var fireButton2 = Input.GetAxisRaw("Fire2") != 0;

        //If Fire1 and not attacking, the player can attack
        if (fireButton1)
        {
            if (isAttackAxisAlreadyDown == false) // gate to only take attack input the frame the butotn is down
            {
                isAttackAxisAlreadyDown = true;
                if (canAttack)
                {
                    stateMachine.RequestChangePlayerState(CharacterStateMachine.CharacterState.attacking);
                    StartCoroutine(ReturnToIdleWhenAttackIsOver());
                }
            }
        }

        if (!fireButton1) // reset attack input gate
        {
            isAttackAxisAlreadyDown = false;
        }

        //Ff Fire2 and there are dashing points available, the player will dash
        if (fireButton2)
        {
            if (isDashAxisAlreadyDown == false) // gate to only take dash input the frame the button is down
            {
                isDashAxisAlreadyDown = true;
                if (canDash)
                {
                    stateMachine.RequestChangePlayerState(CharacterStateMachine.CharacterState.dashing);
                    PerformDashing();
                }
            }
        }

        if (!fireButton2) // reset dash input gate
        {
            isDashAxisAlreadyDown = false;
        }

        //If can move and its not attacking, change the state to walking
        if (canMove)
        {
            MovePlayer();

            if (stateMachine.GetCurrentState() != CharacterStateMachine.CharacterState.dashing)
            {
                if (lastPosition != gameObject.transform.position)
                {
                    stateMachine.RequestChangePlayerState(stateModifier: CharacterStateMachine.CharacterState.walking);
                }
                else
                {
                    stateMachine.RequestChangePlayerState(CharacterStateMachine.CharacterState.idle);
                }
            }
        }

        lastPosition = gameObject.transform.position;
    }