Advertisement
martigpg3

Untitled

Jul 22nd, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5.  
  6. public class PickUpWeapon : MonoBehaviour
  7. {
  8.     public bool isPicked = false;
  9.  
  10.     public Transform plr;
  11.     public Transform itemSlot;
  12.     public GameObject parentOfObject;
  13.  
  14.     public float minRange = 2;
  15.  
  16.     public bool CanHit;
  17.     public bool ready;
  18.     //position
  19.     public float smoothFactor = 0.1f;
  20.     //rotation
  21.     public float smooth = 0.2f;
  22.     void Update()
  23.     {
  24.  
  25.         if (!isPicked)
  26.             inRange();
  27.         if (isPicked)
  28.             WeaponMovementRotation();
  29.     }
  30.  
  31.     private void FixedUpdate()
  32.     {
  33.         if (isPicked) {
  34.             WeaponMovementPosition();
  35.         }
  36.     }
  37.  
  38.     public void inRange()
  39.     {
  40.         float distance = Vector3.Distance(transform.position, plr.transform.position);
  41.         bool CloseEnough = distance < minRange;
  42.  
  43.         if (!CloseEnough)
  44.         {
  45.             return;
  46.         }
  47.  
  48.         isPicked = true;
  49.  
  50.         //parentOfObject.transform.position = itemSlot.position;
  51.         //parentOfObject.transform.rotation = itemSlot.rotation;
  52.  
  53.         //gameObject.layer = LayerMask.NameToLayer("tools");
  54.  
  55.     }
  56.  
  57.     public void WeaponMovementRotation()
  58.     {
  59.         parentOfObject.transform.localRotation = Quaternion.Lerp(parentOfObject.transform.rotation,itemSlot.transform.rotation,smooth * Time.deltaTime);
  60.        
  61.     }
  62.  
  63.     public void WeaponMovementPosition()
  64.     {
  65.         parentOfObject.transform.position = Vector3.Lerp(parentOfObject.transform.position, itemSlot.position, Time.deltaTime * smoothFactor);
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement