daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest Feb 25th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top