Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Spawner : MonoBehaviour {
- public GameObject bulletPrefab;
- public int numberOfBullets;
- public float bulletSpeed;
- // Use this for initialization
- void Start () {
- for (int i = 0; i < numberOfBullets; i++)
- {
- GameObject instantiatedBullet = Instantiate(bulletPrefab, transform, false);
- float angleToSpawnAt = 360f / numberOfBullets * i;
- Rigidbody2D bulletRigidbody = instantiatedBullet.GetComponent<Rigidbody2D>();
- bulletRigidbody.rotation = angleToSpawnAt;
- Vector2 bulletVelocity = new Vector2(Mathf.Sin(Mathf.Deg2Rad * angleToSpawnAt) * bulletSpeed, Mathf.Cos(Mathf.Deg2Rad * angleToSpawnAt) * bulletSpeed);
- bulletRigidbody.velocity = bulletVelocity;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement