SHARE
TWEET

Untitled

a guest Jul 22nd, 2014 228 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Grabber : Weapon
  5. {
  6.     public GameObject parent;
  7.     private bool isEnabled = true;
  8.  
  9.     //Grab related
  10.     public GameObject grabbedObject = null;
  11.  
  12.     public Grabber(GameObject parent)
  13.     {
  14.         prefab = Utils.staticVars.grabber;
  15.         name = "grabber";
  16.         this.parent = parent;
  17.         gunObject = (GameObject)Network.Instantiate(prefab, parent.transform.position, Quaternion.identity, 0);
  18.         gunObject.transform.parent = parent.transform;
  19.     }
  20.  
  21.     public override void PrimaryFire()
  22.     {
  23.         if (grabbedObject == null)
  24.         {
  25.             RaycastHit rayCastHit;
  26.             Physics.Raycast(parent.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 2f)), out rayCastHit);
  27.             if (rayCastHit.collider.gameObject.tag == "Pickable")
  28.             {
  29.                 grabbedObject = rayCastHit.collider.gameObject;
  30.                 grabbedObject.transform.parent = parent.transform;
  31.             }
  32.             else
  33.             {
  34.                 grabbedObject = null;
  35.             }
  36.         }
  37.         else
  38.         {
  39.             grabbedObject.transform.parent = null;
  40.             grabbedObject = null;
  41.         }
  42.     }
  43.  
  44.     public override void SecondaryFire()
  45.     {
  46.         if (grabbedObject != null)
  47.         {
  48.             grabbedObject.transform.parent = null;
  49.             grabbedObject = null;
  50.         }
  51.     }
  52.  
  53.     public override void Unequip()
  54.     {
  55.         //gunObject.renderer.enabled = false;
  56.         isEnabled = false;
  57.         grabbedObject.transform.parent = null;
  58.         grabbedObject = null;
  59.     }
  60.  
  61.     public override void Eqiup()
  62.     {
  63.         //gunObject.renderer.enabled = true;
  64.  
  65.         isEnabled = true;
  66.         grabbedObject = null;
  67.     }
  68.  
  69.     public override void OnUpdate()
  70.     {
  71.         if (grabbedObject != null)
  72.         {
  73.             grabbedObject.rigidbody.velocity = Vector3.zero;
  74.             grabbedObject.rigidbody.angularVelocity = Vector3.zero;
  75.             Vector3 inFrontOfCamera = parent.camera.ViewportToWorldPoint(new Vector3(0.5F, 0.5F, 2));
  76.             grabbedObject.transform.position = inFrontOfCamera;
  77.             grabbedObject.rigidbody.position = inFrontOfCamera;
  78.         }
  79.     }
  80.  
  81. }
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