Ejemplo n.º 1
0
        private void Update()
        {
            if (remainingChargeTime > 0f)
            {
                remainingChargeTime -= Time.deltaTime;
            }

            if (curState == SpikeHeadStateEnum.Idle)
            {
                curVelo = 0f;
                TryDetectPlayer();
            }
            else if (curState == SpikeHeadStateEnum.Staging)
            {
                curVelo             = 0f;
                remainingStageTime -= Time.deltaTime;
                if (!DetectAfterReturned)
                {
                    DetectPlayer();
                }
                if (remainingStageTime <= float.Epsilon)
                {
                    if (GoBackAfterCharged)
                    {
                        curState = SpikeHeadStateEnum.Returning;
                    }
                    else
                    {
                        curState = SpikeHeadStateEnum.Idle;
                    }
                }
            }
            else if (curState == SpikeHeadStateEnum.Returning)
            {
                if (!DetectAfterReturned)
                {
                    DetectPlayer();
                }
            }
            else if (curState == SpikeHeadStateEnum.Preparing)
            {
                remainingPrepareTime -= Time.deltaTime;
                if (remainingPrepareTime <= 0f)
                {
                    curState       = SpikeHeadStateEnum.Charging;
                    animator.speed = 1f;
                    animator.SetBool("Attack", true);
                    ExclamationGO.SetActive(false);
                }
            }
        }
Ejemplo n.º 2
0
        void DetectPlayer()
        {
            if (remainingChargeTime > float.Epsilon)
            {
                return;
            }

            Vector2 origin1 = transform.position;
            Vector2 origin2 = transform.position;

            origin1.y += RayOffset;
            origin2.y -= RayOffset;

            //Check A
            if (HasAlivePlayer(Physics2D.Raycast(origin1, GetDirectionVec(PointA), filter, hitBuffer, GetDistance(PointA))) ||
                HasAlivePlayer(Physics2D.Raycast(origin2, GetDirectionVec(PointA), filter, hitBuffer, GetDistance(PointA))))
            {
                curState             = SpikeHeadStateEnum.Preparing;
                ChargeTarget         = GetChargeTarget(PointA);
                remainingChargeTime  = ChargeCoolDown;
                remainingPrepareTime = PrepareTime;
                animator.SetTrigger("Prepare");
                ExclamationGO.SetActive(true);
                animator.speed = PrepareTime == 0f? 1f : 1f / PrepareTime;
                return;
            }
            //Check B
            if (HasAlivePlayer(Physics2D.Raycast(origin1, GetDirectionVec(PointB), filter, hitBuffer, GetDistance(PointB))) ||
                HasAlivePlayer(Physics2D.Raycast(origin2, GetDirectionVec(PointB), filter, hitBuffer, GetDistance(PointB))))
            {
                curState             = SpikeHeadStateEnum.Preparing;
                ChargeTarget         = GetChargeTarget(PointB);
                remainingChargeTime  = ChargeCoolDown;
                remainingPrepareTime = PrepareTime;
                animator.SetTrigger("Prepare");
                ExclamationGO.SetActive(true);
                animator.speed = PrepareTime == 0f ? 1f : 1f / PrepareTime;
                return;
            }
        }
Ejemplo n.º 3
0
 private void Start()
 {
     curState    = SpikeHeadStateEnum.Idle;
     orgPosition = transform.position;
     ExclamationGO.SetActive(false);
 }
Ejemplo n.º 4
0
        private void FixedUpdate()
        {
            if (curState == SpikeHeadStateEnum.Charging || curState == SpikeHeadStateEnum.Returning)
            {
                Vector2 targetPos = transform.position;
                if (curState == SpikeHeadStateEnum.Charging)
                {
                    curVelo  += Accelaration * Time.deltaTime;
                    targetPos = ChargeTarget;
                }
                else if (curState == SpikeHeadStateEnum.Returning)
                {
                    curVelo   = ReturnSpeed;
                    targetPos = orgPosition;
                }

                float   distanceRemain = 0f;
                Vector2 newVelo;
                if (Direction == DirectionEnum.Horizontal)
                {
                    distanceRemain = Mathf.Abs(targetPos.x - transform.position.x);
                    newVelo        = new Vector2(curVelo, 0f);
                    if (targetPos.x < transform.position.x)
                    {
                        newVelo = -newVelo;
                    }
                }
                else
                {
                    distanceRemain = Mathf.Abs(targetPos.y - transform.position.y);
                    newVelo        = new Vector2(0f, curVelo);
                    if (targetPos.y < transform.position.y)
                    {
                        newVelo = -newVelo;
                    }
                }

                if (distanceRemain < curVelo * Time.deltaTime)
                {
                    //Arrived
                    rb.MovePosition(targetPos);
                    rb.velocity = Vector2.zero;
                    if (curState == SpikeHeadStateEnum.Charging)
                    {
                        SoundManager.Instance.PlaySFX(SoundManager.Instance.SpikeHeadSound, 1f);
                        curState           = SpikeHeadStateEnum.Staging;
                        remainingStageTime = StageTime;
                        if (Direction == DirectionEnum.Horizontal)
                        {
                            animator.SetTrigger("HorizontalHit");
                        }
                        else
                        {
                            animator.SetTrigger("VerticalHit");
                        }
                        animator.SetBool("Attack", false);
                    }
                    else if (curState == SpikeHeadStateEnum.Returning)
                    {
                        curState = SpikeHeadStateEnum.Idle;
                    }
                }
                else
                {
                    rb.velocity = newVelo;
                }
            }
        }