BloodAndGore/Assets/Scripts/Guns/ShotgunBullet.cs
2019-08-18 20:44:12 +03:00

35 lines
1.2 KiB
C#

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);
}
}
}