SHARE
TWEET

Untitled

a guest Feb 14th, 2020 64 in 15 days
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 Shoot : MonoBehaviour
  6. {
  7.     public float bulletSpeed = 10f;
  8.     public int bullet_count = 1;
  9.  
  10.     public float shoot_time = 0.5f;
  11.     private float st;
  12.  
  13.     public GameObject bulletPrefab;
  14.     public Transform firePoint;
  15.  
  16.  
  17.     void Start()
  18.     {
  19.         st = shoot_time;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.         st -= Time.deltaTime;
  26.        
  27.         if (Input.GetButton("Fire1") && st <= 0)
  28.         {
  29.             st = shoot_time;
  30.             Shooting();
  31.         }
  32.  
  33.     }
  34.  
  35.  
  36.  
  37.     void Shooting()
  38.     {
  39.         firePoint.rotation = gameObject.transform.rotation;
  40.  
  41.         for (int i = -bullet_count / 2; i < bullet_count; i++)
  42.         {
  43.             firePoint.rotation = firePoint.rotation * Quaternion.Euler(0, 0, i * 2);
  44.  
  45.             GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
  46.             Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
  47.             rb.AddForce(firePoint.up * bulletSpeed, ForceMode2D.Impulse);
  48.         }
  49.     }
  50. }
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