Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- public class PickUpWeapon : MonoBehaviour
- {
- public bool isPicked = false;
- public Transform plr;
- public Transform itemSlot;
- public GameObject parentOfObject;
- public float minRange = 2;
- public bool CanHit;
- public bool ready;
- //position
- public float smoothFactor = 0.1f;
- //rotation
- public float smooth = 0.2f;
- void FixedUpdate()
- {
- if (!isPicked)
- inRange();
- if (isPicked)
- WeaponMovement();
- }
- public void inRange()
- {
- float distance = Vector3.Distance(transform.position, plr.transform.position);
- bool CloseEnough = distance < minRange;
- if (!CloseEnough)
- {
- return;
- }
- isPicked = true;
- parentOfObject.transform.position = itemSlot.position;
- parentOfObject.transform.rotation = itemSlot.rotation;
- //gameObject.layer = LayerMask.NameToLayer("tools");
- }
- public void WeaponMovement()
- {
- parentOfObject.transform.position = Vector3.Lerp(parentOfObject.transform.position,itemSlot.position, Time.deltaTime * smoothFactor);
- parentOfObject.transform.rotation = Quaternion.Lerp(parentOfObject.transform.rotation,itemSlot.transform.rotation,smooth * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement