Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour {
  6.  
  7. public GameObject bulletPrefab;
  8. public int numberOfBullets;
  9. public float bulletSpeed;
  10.  
  11. // Use this for initialization
  12. void Start () {
  13. for (int i = 0; i < numberOfBullets; i++)
  14. {
  15. GameObject instantiatedBullet = Instantiate(bulletPrefab, transform, false);
  16. float angleToSpawnAt = 360f / numberOfBullets * i;
  17. Rigidbody2D bulletRigidbody = instantiatedBullet.GetComponent<Rigidbody2D>();
  18. bulletRigidbody.rotation = angleToSpawnAt;
  19. Vector2 bulletVelocity = new Vector2(Mathf.Sin(Mathf.Deg2Rad * angleToSpawnAt) * bulletSpeed, Mathf.Cos(Mathf.Deg2Rad * angleToSpawnAt) * bulletSpeed);
  20. bulletRigidbody.velocity = bulletVelocity;
  21. }
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement