Exemplo n.º 1
0
    private void Awake()
    {
        instance = this;

        transform.position = Vector3.zero;

        for (int i = 0; i < _capacity; i++)
        {
            GameObject audioThreatGameObject = new GameObject();
            audioThreatGameObject.tag              = "Audio";
            audioThreatGameObject.layer            = LayerMask.NameToLayer("Audio");
            audioThreatGameObject.transform.parent = transform;
            AudioThreat audioThreat = new AudioThreat();
            audioThreat.transform          = audioThreatGameObject.transform;
            audioThreat.collider           = audioThreatGameObject.AddComponent <SphereCollider>();
            audioThreat.collider.radius    = 0f;
            audioThreat.collider.enabled   = false;
            audioThreat.collider.isTrigger = true;
            Rigidbody rb = audioThreatGameObject.AddComponent <Rigidbody>();
            rb.isKinematic = true;
            audioThreatGameObject.SetActive(false);

            _audioThreats.Add(audioThreat);
        }
    }
Exemplo n.º 2
0
    public IEnumerator DepletionCoroutine(AudioThreat audioThreat)
    {
        float time = 0f;

        while (time <= audioThreat.depletionDelay)
        {
            float normalizedTime = time / audioThreat.depletionDelay;
            audioThreat.collider.radius = Mathf.Lerp(audioThreat.radius, 0, normalizedTime);

            time += Time.deltaTime;

            yield return(null);
        }

        audioThreat.collider.radius = 0f;

        // After the sound is gone
        audioThreat.depletionCoroutine = null;
        audioThreat.active             = false;
        audioThreat.collider.enabled   = false;
        audioThreat.transform.gameObject.SetActive(false);
    }