Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Pickupable1 : MonoBehaviour
- {
- [SerializeField] private GameObject ObjectHolding;
- [SerializeField] private bool isHolding;
- public Transform HoldingLocation;
- [Range(0, 1)] [SerializeField] private float SlerpSpeed;
- public Camera cam;
- public float grabDistance;
- // Start is called before the first frame update
- void Start()
- {
- cam = Camera.main;
- }
- // Update is called once per frame
- void Update()
- {
- Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, grabDistance))
- {
- if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Pickupable"))
- {
- if (Input.GetKeyDown(KeyCode.E))
- {
- ObjectHolding = hit.transform.gameObject;
- isHolding = true;
- }
- }
- }
- if (isHolding == true) ;
- ObjectHolding.transform.position = Vector3.Slerp(ObjectHolding.transform.position, HoldingLocation.transform.position, SlerpSpeed);
- if (isHolding == true && Input.GetKeyDown(KeyCode.E))
- {
- isHolding = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement