Advertisement
Vlad_Savitskiy

Shotgun bullet

Jan 9th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ShotgunBullet : Bullet
  4. {
  5.     private Vector3 _direction;
  6.  
  7.     private void Start()
  8.     {
  9.         var rotatedVector = Vector3.left;
  10.         var bulletRotation = transform.rotation.eulerAngles * Mathf.Deg2Rad;
  11.  
  12.         var x1 = rotatedVector.x * Mathf.Cos(bulletRotation.z) - rotatedVector.y * Mathf.Sin(bulletRotation.z);
  13.         var y1 = rotatedVector.x * Mathf.Sin(bulletRotation.z) + rotatedVector.y * Mathf.Cos(bulletRotation.z);
  14.  
  15.         _direction = new Vector3(x1, y1, 0).normalized * (Speed * Time.deltaTime);
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         transform.Translate(_direction * (Speed * Time.deltaTime), Space.World);
  21.  
  22.         TrySelfDestruction(Time.deltaTime);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement