Advertisement
sergezhu

Airplane

Dec 5th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. public class AirplaneMover : MonoBehaviour
  2. {
  3.     [SerializeField] private float _speed;
  4.  
  5.     private Transform _transform;
  6.  
  7.     private void Awake()
  8.     {
  9.         _transform = transform;
  10.     }
  11.     void Update()
  12.     {
  13.         _transform.position += Vector3.forward * _speed * Time.deltaTime;
  14.     }
  15. }
  16.  
  17.  
  18. //-------------------------------------------------------------------------------------------------------
  19. public class Dropper : MonoBehaviour
  20. {
  21.     [SerializeField] private GameObject _droppedObject;
  22.     [SerializeField] private Transform _dropPoint;
  23.  
  24.     [Range(50, 500)]
  25.     [SerializeField] private float _dropPower = 400;
  26.  
  27.     [Range(.2f, 20)]
  28.     [SerializeField] private float _dropDelay = 1f;
  29.  
  30.     private float _time;
  31.  
  32.  
  33.     private void Start()
  34.     {
  35.         _time = 0;
  36.     }
  37.  
  38.     private void Update()
  39.     {
  40.         _time += Time.deltaTime;
  41.  
  42.         if (_time >= _dropDelay)
  43.         {
  44.             Drop();
  45.             _time = 0;
  46.         }
  47.     }
  48.  
  49.     private void Drop()
  50.     {
  51.         Vector3 force = new Vector3(Random.Range(-0.25f, 0.25f), 0, 1f) * _dropPower;
  52.  
  53.         GameObject droppedItem = Instantiate(_droppedObject, _dropPoint.position, Quaternion.identity);
  54.         droppedItem.GetComponent<Rigidbody>().AddForce(force);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement