コード例 #1
0
 private void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (hitGoal == 1)
        {
            hitGoal = 2;
            circleCollider2D.enabled = false;
            if (audioSource.clip)
            {
                audioSource.Play();
                particleSystem.Play();
            }
            spriteRenderer.enabled = false;
            if (isFakeGoal == false)
            {
                MainSceneManager_script.sceneNum = 2;
            }

            if (isFakeGoal)
            {
                SoundSpawner.PlaySoundObj(transform.position, audioSource.clip);
                spriteRenderer.sprite = null;
            }

            StartCoroutine(WaitBeforeDestroy());
        }
    }
コード例 #3
0
    override public void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        if (animator.transform.name == "Evil Sun")
        {
            SoundSpawner.PlaySoundObj(animator.transform.position, Resources.Load <AudioClip>("Audio/sunThrown"), 1);
            animator.GetComponent <SpriteRenderer>().sprite = sunThrownSprite;
        }
        ThrownVals_script                 = animator.gameObject.GetComponent <ThrownVals>();
        animator.gameObject.layer         = 15;
        projectileHitbox                  = Instantiate(projectileHitbox, animator.transform.position, Quaternion.identity);
        projectileHitbox.transform.parent = animator.gameObject.transform;
        if (ThrownVals_script.regularExplosion)
        {
            projectileHitbox.transform.GetChild(0).GetComponent <ToGoreHitbox>().goreExplosion =
                Resources.Load <GameObject>("Explosion");
        }
        // Instantly kill if the spawn position of the thrown projectile overlaps a layer.

        if (ThrownVals_script.instaKill == false)
        {
            ThrownVals_script.beginMovement = true;
        }



        ThrownVals_script.WaitUntilExploding();
    }
コード例 #4
0
    IEnumerator Bite()
    {
        for (int i = 0; i < Random.Range(3, 4); i++)
        {
            trailRenderer.enabled = false;
            if (health > 0 && biteAmt <= 9)
            {
                currentBiteMoveSpeed  = 0;
                spriteRenderer.sprite = weird;
                ResetRbTransform();
                RandomTeleportLocation();

                yield return(new WaitForSecondsRealtime(0.5f));

                if (health <= maxHealth / 2f)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        // Juke the player
                        if (Random.Range(0, 6) < 3)
                        {
                            ResetRbTransform();
                            RandomTeleportLocation();
                            biteAmt++;
                            yield return(new WaitForSecondsRealtime(0.5f));
                        }
                        else
                        {
                            i = 99;
                        }
                    }
                }

                bitePos = player.transform.position;
                SoundSpawner.PlaySoundObj(transform.position, roar);
                trailRenderer.enabled = true;


                currentBiteMoveSpeed = biteMovementSpeed;



                spriteRenderer.sprite = bite;

                yield return(new WaitForSecondsRealtime(0.4f));

                biteAmt++;
            }
            // Prevent the sun from biting too much.
            if (biteAmt > 9)
            {
                i = 90;
                currentAttackState = (Attack)0;
            }
        }

        currentAttack = null;
    }
コード例 #5
0
 private void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
     }
     else if (_instance != null)
     {
         Destroy(this.gameObject);
     }
 }
コード例 #6
0
    void MissileFire()
    {
        var     newMissile = Instantiate(missile, transform.position + new Vector3(Random.Range(-colliderSize, colliderSize), Random.Range(-colliderSize, colliderSize), 0), Quaternion.identity);
        Vector3 dir        =
            new Vector3(player.transform.position.x + Random.Range(-3, 3), player.transform.position.y,
                        player.transform.position.z) - newMissile.transform.position;
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        newMissile.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        SoundSpawner.PlaySoundObj(transform.position, Resources.Load <AudioClip>("Audio/sunFire"), 1, false, 80, 0.8f);
    }
コード例 #7
0
    IEnumerator DelayBeforeStarting()
    {
        rb.velocity = new Vector2(0, 1);
        yield return(new WaitForSecondsRealtime(3.3f));

        rb.velocity           = new Vector2(0, 0);
        spriteRenderer.sprite = bite;
        yield return(new WaitForSecondsRealtime(0.25f));

        spriteRenderer.sprite = smile;
        SoundSpawner.PlaySoundObj(transform.position, teleportSound);
        particleSystem.Play();
        transform.position = new Vector2(player.transform.position.x + Random.Range(0, 5f), player.transform.position.y + 8f);
        currentAttack      = StartCoroutine(BeginningFiringAtPlayer());
    }
コード例 #8
0
    void RandomTeleportLocation()
    {
        var randomFloatX = (Random.Range(7f, 9f));

        if (Random.value > 0.5f)
        {
            randomFloatX = -randomFloatX;
        }
        var randomFloatY = (Random.Range(3f, 5f));

        if (Random.value > 0.5f)
        {
            randomFloatY = -randomFloatY;
        }
        SoundSpawner.PlaySoundObj(transform.position, teleportSound);
        particleSystem.Play();
        transform.position = new Vector2(player.transform.position.x + randomFloatX, player.transform.position.y + randomFloatY);
    }
コード例 #9
0
    void OnCollisionEnter(Collision collision)
    {
        if (((1 << collision.gameObject.layer) & _hitableLayer) != 0)
        {
            /*
             * 衝突したオブジェクトが _hitableLayerに含まれるとき。
             * LayerMaskは複数のレイヤーを指定できてInspector上では扱いやすいが、
             * データ上はビット演算になっていて、直感的でない。
             * 指定のレイヤーにだけ反応するようにするには、上記の書き方をすると効率的。
             */

            SoundSpawner.GetInstance().Play(_hitTargetSound, collision.contacts [0].point);
        }
        else
        {
            SoundSpawner.GetInstance().Play(_hitOtherSound, collision.contacts [0].point);
        }
        OnHit();
    }
コード例 #10
0
    IEnumerator SunAnimation()
    {
        SoundSpawner.PlaySoundObj(transform.position, roar);
        SoundSpawner.PlaySoundObj(transform.position, roar);
        sunSprite.color = new Color(sunSprite.color.r, sunSprite.color.g, sunSprite.color.b, 1);
        sun.GetComponent <ScrollingEffect>().enabled = false;
        sunSprite.sprite = bite;
        yield return(new WaitForSecondsRealtime(0.1f));

        moveToMeat = true;
        yield return(new WaitForSecondsRealtime(0.1f));

        sunSprite.sprite = evilFace;
        SoundSpawner.PlaySoundObj(transform.position, chomp);
        falseMeat.GetComponent <SpriteRenderer>().enabled = false;
        falseMeat.GetComponent <ParticleSystem>().Play();
        yield return(new WaitForSecondsRealtime(1f));

        sunSprite.sprite = laugh;
        yield return(new WaitForSecondsRealtime(0.3f));

        sunSprite.sprite = evilFace;
        yield return(new WaitForSecondsRealtime(0.3f));

        sunSprite.sprite = laugh;
        yield return(new WaitForSecondsRealtime(0.3f));

        sunSprite.sprite = evilFace;
        yield return(new WaitForSecondsRealtime(0.3f));

        sunSprite.sprite = laugh;
        yield return(new WaitForSecondsRealtime(0.8f));

        sunSprite.sprite = evilFace;
        SceneManager.LoadScene("Level_15");
    }
コード例 #11
0
 private void Awake()
 {
     spawner = GetComponent <SoundSpawner>();
 }
コード例 #12
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Debug.Log("health/maxhealth: " + (float)health / maxHealth);
        spriteRenderer.color = Color.Lerp(Color.white, colorHealth, (float)health / maxHealth);
        if (health < detectHealth)
        {
            detectHealth = health;
            if (health > 0)
            {
                SoundSpawner.PlaySoundObj(transform.position, hurtSound);
            }
            currentBiteMoveSpeed = 0;
        }

        if (health <= 0 && health > -999)
        {
            currentAttack = null;
            GameObject[] missiles = GameObject.FindGameObjectsWithTag("Missile");
            foreach (var missile in missiles)
            {
                missile.GetComponent <Missile>().DestroyImmediately();
            }
            health                = -1000;
            currentAttackState    = Attack.Defeated;
            spriteRenderer.sprite = defeated;
            gameObject.layer      = 13;
            gameObject.tag        = "Enemy";
            animator.enabled      = true;
            hurtHitbox.SetActive(false);
            collider.radius = 1.44f;
            collider.offset = new Vector2(0, 0.66f);
            gameObject.GetComponent <SimpleVals>().enabled = true;
            gameObject.GetComponent <ThrownVals>().enabled = true;
            collider.enabled    = false;
            boxCollider.enabled = true;
            rb.gravityScale     = 1;
            SoundSpawner.PlaySoundObj(transform.position, hurtSound, 1, false, 80, 0.8f);
            SoundSpawner.PlaySoundObj(transform.position, hurtSound, 1, false, 80, 0.8f);
        }

        if (currentAttack == null && health > 0)
        {
            currentAttackState = (Attack)Random.Range(0, 2);
            transform.rotation = quaternion.Euler(0, 0, 0);
            ResetRbTransform();
        }

        switch (currentAttackState)
        {
        case Attack.Missiles:
        {
            trailRenderer.enabled = false;
            if (currentAttack == null && health > 0)
            {
                moveTowards = MoveTowards.Choose;
                SoundSpawner.PlaySoundObj(transform.position, teleportSound);
                particleSystem.Play();
                transform.position = new Vector2(player.transform.position.x + Random.Range(-10, 10f), player.transform.position.y + 8f);
                biteAmt            = 0;
                currentAttack      = StartCoroutine(FiringAtPlayer());
            }
            var     step      = (missileFiringMovementSpeed * lessHealthFasterAttack()) * Time.deltaTime;
            Vector3 chosenPos = Vector3.zero;
            switch (moveTowards)
            {
            case MoveTowards.Choose:
            {
                moveTowards = (MoveTowards)Random.Range(1, 4);
                break;
            }

            case MoveTowards.Left:
            {
                chosenPos = new Vector3(-32, Random.Range(-4f, 2f));
                break;
            }

            case MoveTowards.Right:
            {
                chosenPos = new Vector3(43, Random.Range(-4f, 2f));
                break;
            }

            case MoveTowards.Player:
            {
                chosenPos = new Vector3(player.transform.position.x, Random.Range(-4f, 2f));
                break;
            }
            }
            transform.position =
                Vector2.MoveTowards(transform.position, chosenPos, step);
            if (transform.position.x < -30)
            {
                transform.position = new Vector3(player.transform.position.x, 0) + new Vector3(Random.Range(0, 10f), 0);
                SoundSpawner.PlaySoundObj(transform.position, teleportSound);
                particleSystem.Play();
                if (Random.value > 0.5f)
                {
                    moveTowards = MoveTowards.Right;
                }
                else
                {
                    moveTowards = MoveTowards.Player;
                }
            }
            if (transform.position.x > 41)
            {
                transform.position = new Vector3(player.transform.position.x, 0) + new Vector3(Random.Range(-10f, 0f), 0);
                SoundSpawner.PlaySoundObj(transform.position, teleportSound);
                particleSystem.Play();
                if (Random.value > 0.5f)
                {
                    moveTowards = MoveTowards.Left;
                }
                else
                {
                    moveTowards = MoveTowards.Player;
                }
            }
            transform.position = new Vector3(transform.position.x, (Mathf.Sin(Time.time * (lessHealthFasterAttack() * 6.5f)) * lessHealthFasterAttack()));
            if (transform.position.y > 0)
            {
                spriteRenderer.sprite = laugh;
                if (canFireMissile)
                {
                    canFireMissile = false;
                    MissileFire();
                }
            }
            if (transform.position.y <= 0)
            {
                spriteRenderer.sprite = smile;
                canFireMissile        = true;
            }

            break;
        }

        case Attack.Bite:
        {
            if (currentAttack == null && health > 0)
            {
                currentAttack = StartCoroutine(Bite());
            }
            var step = currentBiteMoveSpeed * Time.deltaTime;
            transform.position =
                Vector2.MoveTowards(transform.position, bitePos, step);
            break;
        }

        case Attack.Defeated:
        {
            spriteRenderer.sprite = defeated;
            trailRenderer.enabled = false;
            currentAttack         = null;
            break;
        }
        }
    }