Pro_Unit

Projectile

May 8th, 2021 (edited)
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. [RequireComponent(typeof(Rigidbody))]
  2. public class Projectile : MonoBehaviour
  3. {
  4.     [SerializeField] private float _speed = 100f;
  5.    
  6.     [SerializeField] private Rigidbody _rigidbody;
  7.  
  8.     private void Reset() =>
  9.         _rigidbody = GetComponent<Rigidbody>();
  10.  
  11.     public void Setup(Vector3 direction) =>
  12.         transform.forward = direction.normalized;
  13.  
  14.     private void FixedUpdate() =>
  15.         _rigidbody.velocity = transform.forward * (_speed * Time.deltaTime);
  16. }
Add Comment
Please, Sign In to add comment