private void Update() { obj.UpdateFlow(); var onScreen = SpawnFieldManager.instance.worldCameraRect.Contains(transform.position); if (onScreen) { activeInScene = true; } if (!onScreen && !activeInScene) { passiveDeathTimer -= Time.deltaTime; } if (obj.flowVelocity == Vector3.zero || (!onScreen && activeInScene) || passiveDeathTimer < 0) { Destroy(gameObject); } var color = sprite.color; color.a = Mathf.Lerp(0, 1, obj.flowVelocity.magnitude / 0.4f); sprite.color = color; }
void Update() { obj.UpdateFlow(); if (chasing) { if (target) { var dir = target.position - transform.position; if (dir.magnitude > 8) { target = null; chasing = false; } velocity = dir.normalized * movementSpeed; } else { chasing = false; target = null; } } else { idleTimer -= Time.deltaTime; if (idleTimer < 0) { idleTimer += UnityEngine.Random.Range(2, 5); var targetPos = transform.position + (Vector3)UnityEngine.Random.insideUnitCircle * 5f; var dir = targetPos - transform.position; velocity = dir.normalized * movementSpeed; } } var mag = velocity.magnitude; mag -= 1f * Time.deltaTime; if (mag < 0) { mag = 0; } velocity = velocity.normalized * mag; if (velocity.magnitude > 0.001f) { if (Vector3.Dot(velocity.normalized, Vector3.right) > 0) { sprite.flipY = true; } else { sprite.flipY = false; } var rotation = Quaternion.LookRotation(velocity, Vector3.forward); rotation *= Quaternion.AngleAxis(90, Vector3.right); rotation *= Quaternion.AngleAxis(90, Vector3.forward); sprite.transform.rotation = rotation; } if (chasing) { sprite.transform.localScale = new Vector3(initialScale.x, Mathf.Lerp(initialScale.y * 0.75f, initialScale.y, (Mathf.Sin(Time.time * 8) + 1) * 0.5f), initialScale.z); } else { sprite.transform.localScale = new Vector3(initialScale.x, Mathf.Lerp(initialScale.y * 0.75f, initialScale.y, squishCurve.Evaluate(1 - (velocity.magnitude / movementSpeed))), initialScale.z); } }