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; } } }
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(); }
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; } } } }
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(); } } } }
public override void Update() { if (!dead && !antiBodyDisable && dispersionCooldown.CountDown()) { disperse = !disperse; } base.Update(); }
void IdleCount() { idleToggleCooldown.CountDown(); if (idleToggleCooldown.TriggerReady(transformingTrigger: Random.Range(6f, 10f))) { previousState = state; state = EnemyState.idle; } }
private void Update() { // if day if (true && currentGrow < maxGrow) { cooldown.CountDown(); if (cooldown.TriggerReady()) { SpawnFruit(GetPoint()); } } }
private void Update() { if (!isDead) { if (moveCooldown.CountDown()) { RandomMovement(); } RadialDetection(); } ScrollCell(); }
public virtual void Update() { if (!dead && !antiBodyDisable) { RadialDetection(); ScrollCell(); } if (antiBodyDisable && disableCooldown.CountDown()) { antiBodyDisable = false; } GetComponent <SpriteRenderer>().sprite = antiBodyDisable ? disabledSprite : originalSprite; }
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(); } } }
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); } } }
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(); } }
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; } }
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! } }
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; } } }
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; } } }
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; } } }
void Update() { bossAttackCooldown.CountDown(); }
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; * }*/ }