BloodAndGore/Assets/Scripts/Guns/ShotgunBullet.cs

35 lines
1.2 KiB
C#
Raw Permalink Normal View History

2019-08-18 19:44:12 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Saltosion.OneWeapon.Guns {
public class ShotgunBullet : MonoBehaviour {
public Bullet SubBullet;
public int BulletsShot;
public float TotalArc;
private Bullet Bullet;
void Start() {
Bullet = GetComponent<Bullet>();
Vector2 Direction = Bullet.Direction;
float Rot = Bullet.InitialRotation;
Vector2 BaseDirection = Quaternion.AngleAxis(TotalArc / 2, Vector3.forward) * Direction;
float Rotation = Mathf.Atan2(BaseDirection.y, BaseDirection.x) * Mathf.Rad2Deg + 90;
for (int i = 0; i < BulletsShot; i++) {
float CurrentAngle = -i * (TotalArc / (BulletsShot - 1));
Vector2 CurrentDirection = Quaternion.AngleAxis(CurrentAngle, Vector3.forward) * BaseDirection;
Bullet ShotBullet = GameObject.Instantiate(SubBullet, transform.position, new Quaternion());
ShotBullet.Direction = CurrentDirection;
ShotBullet.InitialRotation = Rotation + CurrentAngle;
}
Destroy(gameObject);
}
}
}