示例#1
0
	// Use this for initialization
	void Start () {
        state = MiniBoidState.Disabled;

        effectsEnabled = true;
        EnableEffects(false);

        noiseOffset = Random.Range(0f, 10f);
	}
示例#2
0
	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);
        }
	}
示例#3
0
 public override void Deactivate() {
     StopAllCoroutines();
     state = MiniBoidState.Pooled;
     EnableEffects(false);
     gameObject.SetActive(false);
 }
示例#4
0
 public override void Activate() {
     gameObject.SetActive(true);
     EnableEffects(true);
     state = MiniBoidState.Flying;
 }
示例#5
0
    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());
    }
示例#6
0
    private IEnumerator CleanupRoutine() {
        state = MiniBoidState.CleanUp;

        float time = EnableEffects(false, false);
        yield return new WaitForSeconds(time);

        ReturnToPool();
    }
示例#7
0
    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;
    }