private void Update()
 {
     if (started)
     {
         if (startTimer < 0)
         {
             rb.gravityScale = 0;
             rb.drag         = 5;
             if (active)
             {
                 if (c.CountDown(true, Random.Range(0.1f, 10f)))
                 {
                     dir = !dir;
                 }
                 rb.AddForce(new Vector2(dir ? -2 : 2, 0).normalized *Random.Range(2f, 3f) - (Vector2.up * 2f));
             }
             else
             {
                 rb.velocity        = Vector2.zero;
                 rb.angularVelocity = 0;
             }
         }
         else
         {
             startTimer -= Time.deltaTime;
         }
     }
 }
예제 #2
0
 public override void Update()
 {
     if (!dead && !antiBodyDisable && dispersionCooldown.CountDown())
     {
         disperse = !disperse;
         if (disperse)
         {
             sticking = false;
         }
     }
     if (!dead && !antiBodyDisable && attractionCooldown.CountDown())
     {
         attracting = !attracting;
     }
     if (antiBodyDisable)
     {
         sticking = false;
     }
     rb.isKinematic = sticking;
     if (sticking)
     {
         rb.velocity        = Vector2.zero;
         rb.angularVelocity = 0;
     }
     base.Update();
 }
예제 #3
0
 void IdleCountDown()
 {
     if (target == null || idling)
     {
         if (idling)
         {
             if (target != null)
             {
                 Vector3 dir = target.position - transform.position;
                 transform.localScale = new Vector3(dir.x > 0 ? -1 : 1, 1, 1);
             }
             anim.SetBool("Walking", false);
             idleCooldown.CountDown();
             if (idleCooldown.TriggerReady(transformingTrigger: target == null ? Random.Range(6f, 12f) : Random.Range(1f, 3f)))
             {
                 idling = false;
             }
         }
         else
         {
             idleToggleCooldown.CountDown();
             if (idleToggleCooldown.TriggerReady(transformingTrigger: Random.Range(6f, 12f)))
             {
                 idling = true;
             }
         }
     }
 }
예제 #4
0
        private void Update()
        {
            if (growthling != null)
            {
                if (growthlingSize < 0f)
                {
                    growthlingSize = 0f;
                    growthling.transform.localScale = new Vector3(0, 0, 0);
                    DetachGrowthling();
                }
            }

            if (started)
            {
                Run();
                if (c.CountDown())
                {
                    for (int i = 0; i < leafList.Count; i++)
                    {
                        leafList[i].ReEvaluateLeaf();
                        leafList[i].CheckDown();
                        leafList[i].CheckUp();
                    }
                    for (int i = 0; i < rootList.Count; i++)
                    {
                        rootList[i].Refresh();
                    }
                }
            }
        }
예제 #5
0
 public override void Update()
 {
     if (!dead && !antiBodyDisable && dispersionCooldown.CountDown())
     {
         disperse = !disperse;
     }
     base.Update();
 }
예제 #6
0
 void IdleCount()
 {
     idleToggleCooldown.CountDown();
     if (idleToggleCooldown.TriggerReady(transformingTrigger: Random.Range(6f, 10f)))
     {
         previousState = state;
         state         = EnemyState.idle;
     }
 }
예제 #7
0
 private void Update()
 {
     // if day
     if (true && currentGrow < maxGrow)
     {
         cooldown.CountDown();
         if (cooldown.TriggerReady())
         {
             SpawnFruit(GetPoint());
         }
     }
 }
예제 #8
0
    private void Update()
    {
        if (!isDead)
        {
            if (moveCooldown.CountDown())
            {
                RandomMovement();
            }
            RadialDetection();
        }

        ScrollCell();
    }
예제 #9
0
 public virtual void Update()
 {
     if (!dead && !antiBodyDisable)
     {
         RadialDetection();
         ScrollCell();
     }
     if (antiBodyDisable && disableCooldown.CountDown())
     {
         antiBodyDisable = false;
     }
     GetComponent <SpriteRenderer>().sprite = antiBodyDisable ? disabledSprite : originalSprite;
 }
예제 #10
0
 void Update()
 {
     if (!HealthController.dead)
     {
         shooter.rotation = Quaternion.Slerp(shooter.rotation, desiredRot, 5f * Time.deltaTime);
         cooldown.CountDown(Time.deltaTime);
         if (cooldown.TriggerReady())
         {
             GameObject go = Instantiate(circle, shooter.position + shooter.up * 0.3f, Quaternion.identity);
             go.GetComponent <Rigidbody2D>().AddForce(shooter.up * Random.Range(6f, 9f), ForceMode2D.Impulse);
             desiredRot = RandomRot();
         }
     }
 }
예제 #11
0
 private void Update()
 {
     if (active)
     {
         dropActivationCooldown.CountDown();
         if (dropActivationCooldown.TriggerReady(false))
         {
             col.isTrigger      = true;
             rb.useGravity      = false;
             rb.isKinematic     = true;
             gameObject.layer   = 12;
             transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
         }
     }
 }
예제 #12
0
 void Trail()
 {
     if (Xor(!IsGrounded, trailActivation))
     {
         trailCooldown.CountDown();
         if (trailCooldown.TriggerReady())
         {
             GameObject go = Instantiate(trailObject, transform.position, trailGuide.rotation);
             go.transform.localScale = new Vector3(transform.localScale.x * go.transform.localScale.x, transform.localScale.y * go.transform.localScale.y, transform.localScale.z * go.transform.localScale.z);
         }
     }
     else
     {
         trailCooldown.Zero();
     }
 }
예제 #13
0
 private void FixedUpdate()
 {
     transform.position = Vector2.MoveTowards(transform.position, (Vector2)startingPoint + positions[pointIndex], platformSpeed * Time.fixedDeltaTime);
     if ((Vector2)transform.position == (Vector2)startingPoint + positions[pointIndex])
     {
         stoppingTime.CountDown();
         if (stoppingTime.TriggerReady())
         {
             pointIndex++;
             if (pointIndex >= positions.Length)
             {
                 pointIndex = 0;
             }
         }
     }
 }
        public void Update()
        {
            moisture -= moistureDecreaseRate * Time.deltaTime;
            if (moisture <= 0)
            {
                moisture = 0;
            }
            if (currentCloud == null && rainC.CountDown())
            {
                CheckForRain();
            }

            if (currentCloud != null)
            {
                moisture = 1f;
            }
        }
예제 #15
0
    void Chase()
    {
        combatChaseCooldown.CountDown();
        if (!combatChaseCooldown.TriggerReady(false))
        {
            if (Vector3.Distance(transform.position, nextChasePos) < 0.5f || nextChasePos == Vector3.zero)
            {
                Vector3 dir = transform.position - target.position;
                dir.y = 0;
                dir.z = 0;
                dir.Normalize();

                Collider[] ground = Physics.OverlapSphere(transform.position + (dir * chaseFluctuationMultiplier), 0.1f, groundLayer);

                nextChasePos   = (ground.Length > 0 ? transform.position : target.position) + ((ground.Length > 0 ? -dir : -dir) * chaseFluctuationMultiplier);
                nextChasePos.y = transform.position.y;
                combatChaseCooldown.Zero();
            }
            FaceTowards(nextChasePos);
            //TODO: add movement!
        }
        else
        {
            if (Vector3.Distance(transform.position, nextChasePos) < 0.5f || nextChasePos == Vector3.zero)
            {
                Vector3 dir = transform.position - target.position;
                dir.y = 0;
                dir.z = 0;
                dir.Normalize();

                Collider[] ground = Physics.OverlapSphere(new Vector3(target.position.x + (dir.x * chaseFluctuationMultiplier), transform.position.y, transform.position.z), 0.1f, groundLayer);

                if (ground.Length > 0)
                {
                    state        = EnemyState.idle;
                    nextChasePos = Vector3.zero;
                    return;
                }

                nextChasePos   = new Vector3(target.position.x + (dir.x * chaseFluctuationMultiplier), transform.position.y, transform.position.z);
                nextChasePos.y = transform.position.y;
            }
            FaceTowards(nextChasePos);
            //TODO: add movement!
        }
    }
예제 #16
0
    private void Update()
    {
        if (!dead)
        {
            switch (state)
            {
            case EnemyState.idle:
                anim.SetBool("Walking", false);
                rb.velocity = Vector3.zero;
                Vision();

                idleCooldown.CountDown();
                if (idleCooldown.TriggerReady())
                {
                    state = previousState;
                }
                break;

            case EnemyState.patrolling:
                anim.SetBool("Walking", true);
                IdleCount();
                Vision();
                Turn();
                Patrol();
                Move();
                break;

            case EnemyState.chasing:
                anim.SetBool("Walking", true);
                Vision();
                IdleCount();
                Chase();
                Move();
                break;

            case EnemyState.attacking:
                anim.SetBool("Walking", false);
                rb.velocity = Vector3.zero;
                break;

            case EnemyState.knocked:
                anim.SetBool("Walking", false);
                break;
            }
        }
    }
예제 #17
0
 void Attack()
 {
     attackCooldown.CountDown();
     if (attackCooldown.TriggerReady(transformingTrigger: attackCooldowns[attackIndex]) && AttackInput && Stats.lightLevel > 15f)
     {
         if (!attacking)
         {
             attacking = true;
             StartCoroutine(AttackSequence());
         }
         Stats.LightLevels(-15f);
         AudioController.PlayAudio(transform.position, audioClips.jumpSound, 1f, 0.9f);
         anim.SetTrigger("Attack");
         StopCoroutine(T());
         StartCoroutine(T());
         GameObject go = Instantiate(slashObject, slashPoint.position, Quaternion.identity);
         go.transform.localScale = transform.localScale;
         attackIndex++;
         if (attackIndex >= 2)
         {
             attackIndex = 0;
         }
     }
 }
예제 #18
0
    void Chase()
    {
        /*if(runOpposite)
         * {
         *
         * }*/
        if (idling || attacking)
        {
            return;
        }
        if (!running)
        {
            if (Vector3.Distance(transform.position, target.position) < attackDistance)
            {
                stopWaitCooldown.CountDown();
                if (stopWaitCooldown.TriggerReady())
                {
                    Attack();
                }
                return;
            }

            Vector3 dir = target.position - transform.position;
            dir.y = 0;
            dir.Normalize();
            anim.SetBool("Walking", true);
            rb.velocity          = dir * speed;
            transform.localScale = new Vector3(rb.velocity.x < 0 ? 1 : -1, 1, 1);
            bool       seesWall   = Physics.Raycast(transform.position, dir, wallCheckDistance, groundLayer);
            Collider[] ground     = Physics.OverlapSphere((Vector2)transform.position + (dir.x > 0 ? groundChecks[0] : groundChecks[1]), 0.1f, groundLayer);
            bool       groundLost = ground.Length < 1;

            if (seesWall || groundLost)
            {
                rb.velocity = Vector3.zero;
                target      = null;
                idling      = true;
                idleCooldown.Set(Random.Range(1f, 2f));
                return;
            }
        }
        else
        {
            Vector3 dir = transform.position - target.position;
            dir.y = 0;
            dir.Normalize();
            anim.SetBool("Walking", true);
            rb.velocity          = dir * speed;
            transform.localScale = new Vector3(rb.velocity.x < 0 ? 1 : -1, 1, 1);

            RaycastHit hit;
            bool       seesWall = Physics.Raycast(transform.position, dir, out hit, wallCheckDistance, groundLayer);

            /*if(Vector3.Distance(transform.position, hit.point) < oppositeTreshold && Vector3.Distance(transform.position, target.position) < oppositeTreshold)
             * {
             *  runOpposite = true;
             *  return;
             * }*/
            Collider[] ground     = Physics.OverlapSphere((Vector2)transform.position + (dir.x > 0 ? groundChecks[0] : groundChecks[1]), 0.1f, groundLayer);
            bool       groundLost = ground.Length < 1;
            if (seesWall || groundLost)
            {
                rb.velocity = Vector3.zero;
                idling      = true;
                idleCooldown.Set(1.5f);
                running = false;
                return;
            }
        }
    }
예제 #19
0
 void Update()
 {
     bossAttackCooldown.CountDown();
 }
예제 #20
0
    void Jump()
    {
        if (/*IsGrounded ||*/ !JumpInput)
        {
            jumped = false;

            jumpCooldown.Reset();
        }
        if (jumped)
        {
            jumpCooldown.CountDown();
        }

        if (Input.GetKeyDown(KeyCode.Space) && IsGrounded)
        {
            pressed = true;
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            pressed = false;
        }

        if (IsGrounded && !triggered)
        {
            triggered = true;
            spent     = false;
            StopCoroutine(T());
            StartCoroutine(T(0.4f));
            CameraFollow.CameraShake();
            AudioController.PlayAudio(transform.position, audioClips.landingSound, 0.5f, 0.9f);
        }
        else if (!IsGrounded)
        {
            triggered = false;
        }



        if (!IsGrounded && pressed)
        {
            if (jumpCooldown.LowerThan(jumpCooldown.delay / 2f) && Stats.lightLevel > 0 && JumpInput)
            {
                Stats.LightLevels((-30f - (inLight ? 15f : 0f)) * Time.deltaTime);
                spent = true;
            }
            else
            {
                spent = false;
            }
        }

        if (!IsGrounded && !pressed && rb.velocity.y > 0 || !IsGrounded && jumpCooldown.TriggerReady(false) && rb.velocity.y > 0 || !IsGrounded && !spent && jumpCooldown.LowerThan(jumpCooldown.delay / 2f) && rb.velocity.y > 0)
        {
            Vector3 v = rb.velocity;
            v.y         = Mathf.MoveTowards(v.y, 0, 35f * Time.deltaTime);
            rb.velocity = v;
        }

        if (rb.velocity.y < 0 && !IsGrounded)
        {
            rb.AddForce(Vector3.down * 19.81f, ForceMode.Acceleration);
        }
        if (IsGrounded)
        {
            rb.useGravity = false;
        }
        else
        {
            rb.useGravity = true;
        }
        rb.useGravity = !jumped || jumpCooldown.TriggerReady(false);

        if (IsGrounded && JumpInput && !jumpCooldown.TriggerReady(false) && pressed)
        {
            if (!jumped)
            {
                AudioController.PlayAudio(transform.position, audioClips.jumpSound, 0.7f, 1.5f);
                jumped = true;
                anim.SetTrigger("Jump");
            }
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
        }
        else
        {
            if (jumped)
            {
                anim.ResetTrigger("Jump");
            }
        }


        /*if (attacking)
         * {
         *  return;
         * }*/
    }