Advertisement
martigpg3

Untitled

Jul 22nd, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 FixedUpdate()
  23.     {
  24.  
  25.         if (!isPicked)
  26.             inRange();
  27.         if (isPicked)
  28.             WeaponMovement();
  29.     }
  30.  
  31.     public void inRange()
  32.     {
  33.         float distance = Vector3.Distance(transform.position, plr.transform.position);
  34.         bool CloseEnough = distance < minRange;
  35.  
  36.         if (!CloseEnough)
  37.         {
  38.             return;
  39.         }
  40.  
  41.         isPicked = true;
  42.  
  43.         parentOfObject.transform.position = itemSlot.position;
  44.         parentOfObject.transform.rotation = itemSlot.rotation;
  45.  
  46.         //gameObject.layer = LayerMask.NameToLayer("tools");
  47.  
  48.     }
  49.  
  50.     public void WeaponMovement()
  51.     {
  52.         parentOfObject.transform.position = Vector3.Lerp(parentOfObject.transform.position,itemSlot.position, Time.deltaTime * smoothFactor);
  53.         parentOfObject.transform.rotation = Quaternion.Lerp(parentOfObject.transform.rotation,itemSlot.transform.rotation,smooth * Time.deltaTime);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement