//creates a nova of bullets void Nova() { Vector3 localShotPos = new Vector3(0, -((new Vector2(transform.localScale.x * offset, transform.localScale.y * offset)).magnitude)); //calculates degree intervals based on number of shots float degree = 360f / numberOfShots; for (float i = -180f; i < 180f; i += degree) { Quaternion rotation = Quaternion.AngleAxis(i, transform.forward); //calculate position to instantiate the projectile Vector3 shotPosition = transform.position + rotation * localShotPos; Projectile beam = (Projectile)Instantiate(projectile, shotPosition, rotation * transform.rotation); //calculate vector x and y by using angle velocityOnX = Mathf.Sin((i * Mathf.PI) / 180); //convert actual degrees to radians velocityOnY = Mathf.Cos((i * Mathf.PI) / 180); beam.GetComponent <Rigidbody2D>().velocity = new Vector2(velocityOnX * projectileSpeed, -velocityOnY * projectileSpeed); } //play sound effect. Sound effect should be played only once boomSound = GetComponent <ShootSoundController>(); boomSound.PlaySoundEffect(); }
// Use this for initialization void Start() { float distance = transform.position.z - Camera.main.transform.position.z; Vector3 leftmost = Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, distance)); Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1F, 0f, distance)); //set the borders of the restains of movements xmin = leftmost.x + padding; xmax = rightmost.x - padding; //get current health from static variable health = maxHealth; healthKeeper = GameObject.Find("Health2").GetComponent <HealthKeeper>(); healthKeeper.DisplayHealth(health); shootSound = GetComponent <ShootSoundController>(); }
// Use this for initialization void Start() { shootSound = GetComponent <ShootSoundController>(); }