Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Pickupable1 : MonoBehaviour
  6. {
  7.  
  8.  
  9.     [SerializeField] private GameObject ObjectHolding;
  10.     [SerializeField] private bool isHolding;
  11.     public Transform HoldingLocation;
  12.  
  13.     [Range(0, 1)] [SerializeField] private float SlerpSpeed;
  14.     public Camera cam;
  15.  
  16.  
  17.     public float grabDistance;
  18.  
  19.  
  20.  
  21.     // Start is called before the first frame update
  22.     void Start()
  23.     {
  24.  
  25.         cam = Camera.main;
  26.     }
  27.  
  28.     // Update is called once per frame
  29.     void Update()
  30.     {
  31.  
  32.         Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
  33.         RaycastHit hit;
  34.  
  35.         if (Physics.Raycast(ray, out hit, grabDistance))
  36.         {
  37.  
  38.             if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Pickupable"))
  39.             {
  40.  
  41.                 if (Input.GetKeyDown(KeyCode.E))
  42.                 {
  43.                     ObjectHolding = hit.transform.gameObject;
  44.                     isHolding = true;
  45.                 }
  46.             }
  47.         }
  48.         if (isHolding == true) ;
  49.         ObjectHolding.transform.position = Vector3.Slerp(ObjectHolding.transform.position, HoldingLocation.transform.position, SlerpSpeed);
  50.  
  51.         if (isHolding == true && Input.GetKeyDown(KeyCode.E))
  52.         {
  53.             isHolding = false;
  54.         }
  55.     }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement