Advertisement
Pro_Unit

PlayerHands

Aug 23rd, 2022
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using DG.Tweening;
  2. using UnityEngine;
  3.  
  4. public class PlayerHands : MonoBehaviour
  5. {
  6.     [SerializeField] private Transform _holderPoint;
  7.    
  8.     [SerializeField] private float _collectTime = 0.5f;
  9.     [SerializeField] private float _boxSize = 1f;
  10.  
  11.     private float _lastMoveStart;
  12.     private IItemContainer _currentContainer;
  13.  
  14.     public void StartCollectItems(IItemContainer container) => _currentContainer = container;
  15.  
  16.     public void StopCollect() => _currentContainer = null;
  17.  
  18.     private void Update()
  19.     {
  20.         if (_currentContainer == null)
  21.             return;
  22.  
  23.         if (_currentContainer.Items.Count == 0)
  24.         {
  25.             StopCollect();
  26.             return;
  27.         }
  28.  
  29.         if (_lastMoveStart + _collectTime > Time.time)
  30.             return;
  31.  
  32.         _lastMoveStart = Time.time;
  33.  
  34.         Transform item = _currentContainer.Items.Pop();
  35.  
  36.         item.SetParent(_holderPoint);
  37.  
  38.         Vector3 localPoint = _holderPoint.childCount * _boxSize  * Vector3.up;
  39.            
  40.         item.DOLocalMove(localPoint, _collectTime);
  41.         item.DOLocalRotateQuaternion(Quaternion.identity, _collectTime);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement