// Use this for initialization void Start () { state = MiniBoidState.Disabled; effectsEnabled = true; EnableEffects(false); noiseOffset = Random.Range(0f, 10f); }
public void UpdatePosition (Vector3 playerPosition, Vector3 playerVelocity) { Vector3 toPlayer = playerPosition - transform.position; float toPlayerDist = toPlayer.magnitude; // disable at set distance if (state == MiniBoidState.Flying && toPlayerDist > maxDist) { state = MiniBoidState.Disabled; EnableEffects(false); } else if (state == MiniBoidState.Disabled && toPlayerDist <= maxDist) { state = MiniBoidState.Flying; EnableEffects(true); } if (state == MiniBoidState.Flying || state == MiniBoidState.Landing) { FlyUpdate(playerPosition, playerVelocity); } }
public override void Deactivate() { StopAllCoroutines(); state = MiniBoidState.Pooled; EnableEffects(false); gameObject.SetActive(false); }
public override void Activate() { gameObject.SetActive(true); EnableEffects(true); state = MiniBoidState.Flying; }
private IEnumerator LandingRoutine() { state = MiniBoidState.Landing; float defaultSpeed = speed; float defaultRotSpeed = rotSpeed; while ((transform.position - target.transform.position).magnitude > goalRadiusEpsilon) { speed *= 1f - (0.1f * Time.deltaTime); rotSpeed *= 1f + (1f * Time.deltaTime); yield return null; } transform.position = target.transform.position; speed = defaultSpeed; rotSpeed = defaultRotSpeed; StartCoroutine(CleanupRoutine()); }
private IEnumerator CleanupRoutine() { state = MiniBoidState.CleanUp; float time = EnableEffects(false, false); yield return new WaitForSeconds(time); ReturnToPool(); }
private IEnumerator LaunchRoutine(Vector3 direction) { state = MiniBoidState.Launching; Vector3 launchVel = direction.normalized * speed; for (float timer = 0f; timer < launchTime; timer += Time.deltaTime) { velocity = launchVel; transform.position += velocity * Time.deltaTime; transform.LookAt(transform.position + velocity, Vector3.up); yield return null; } state = MiniBoidState.Flying; }