Esempio n. 1
0
    void SpawnChildren()
    {
        _hasSpawnedChildren = true;

        float angleInterval = spread / count;
        float angle         = Mathf.Atan2(_bullet.velocity.y, _bullet.velocity.x) * Mathf.Rad2Deg;

        float minAngle = angle - spread / 2;
        float maxAngle = angle + spread / 2;

        for (float a = minAngle; a <= maxAngle; a += angleInterval)
        {
            // Calculate velocity
            Vector2 velocity = new Vector2(
                Mathf.Cos(a * Mathf.Deg2Rad),
                Mathf.Sin(a * Mathf.Deg2Rad)
                );

            // Instantiate child
            GameObject child       = Instantiate(gameObject, transform.position, Quaternion.identity);
            Bullet     childBullet = child.GetComponent <Bullet>();
            childBullet.velocity = velocity;
            SprayBullet childSprayBullet = child.GetComponent <SprayBullet>();
            childSprayBullet.isParent = false;
        }

        // Destroy self
        Destroy(gameObject);
    }
Esempio n. 2
0
 public void Update()
 {
     if (playerController.controlEnabled)
     {
         if (playerWeaponController.HasWeapon() && sprayDuration > 0)
         {
             if (canShoot && Input.GetKey(KeyCode.T))
             {
                 if (playerController.IsFacingRight())
                 {
                     playerDir.y = 0;
                     dir         = 1;
                 }
                 else
                 {
                     playerDir.y = 180;
                     dir         = -1;
                 }
                 SprayBullet sprayBullet = Instantiate(sprayParticles, sprayPosition.position, Quaternion.Euler(playerDir)).GetComponent <SprayBullet>();
                 audioSource.Play();
                 sprayBullet.velocity = playerController.velocity.x;
                 sprayBullet.dir      = dir;
                 sprayBullet.damage   = sprayScriptable.damage;
                 sprayDuration       -= 20;
                 if (sprayDuration <= 0 && !rechargingSpray)
                 {
                     rechargingSpray = true;
                     StartCoroutine(RechargeSpray());
                 }
             }
         }
     }
 }