SHARE
TWEET

Untitled

a guest Mar 16th, 2017 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CubePickup : MonoBehaviour {
  6.  
  7.     private GameObject m_Player;
  8.     private GameObject m_onHand;
  9.     private GameObject m_Wall;
  10.     private List<GameObject> m_puzzleSlot;
  11.  
  12.     private bool m_pickedUp = false;
  13.  
  14.     // Use this for initialization
  15.     void Start () {
  16.         //Initializing GameObjects
  17.         m_Player = GameObject.FindGameObjectWithTag("Player");
  18.         m_onHand = GameObject.FindGameObjectWithTag("OnHandPosition");
  19.         m_Wall = GameObject.Find("Wall");
  20.  
  21.         m_puzzleSlot = new List<GameObject>(4);
  22.         m_puzzleSlot.Add(GameObject.Find("Slot001"));
  23.         m_puzzleSlot.Add(GameObject.Find("Slot002"));
  24.         m_puzzleSlot.Add(GameObject.Find("Slot003"));
  25.         m_puzzleSlot.Add(GameObject.Find("Slot004"));
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update () {
  30.         //Local Variables
  31.         float distance_block;
  32.         float distance_wall;
  33.  
  34.         //Initializing distances
  35.         distance_block = Vector3.Distance(m_Player.transform.position, transform.position);
  36.         distance_wall = Vector3.Distance(m_Player.transform.position, m_Wall.transform.position);
  37.  
  38.         //Pickup item Handler
  39.         if (Input.GetButtonDown("Fire3") && distance_block < 3)
  40.         {
  41.             m_pickedUp = !m_pickedUp;
  42.         }
  43.  
  44.         if (m_pickedUp)
  45.         {
  46.             GetComponent<Rigidbody>().useGravity = false;
  47.             transform.position = m_onHand.transform.position;
  48.  
  49.             if (Input.GetButtonDown("PlaceBlock"))
  50.             {
  51.                 //Place the object in the right slot
  52.             }
  53.         }
  54.         else
  55.         {
  56.             GetComponent<Rigidbody>().useGravity = true;
  57.         }
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top