Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Grabber : Weapon
- {
- public GameObject parent;
- private bool isEnabled = true;
- //Grab related
- public GameObject grabbedObject = null;
- public Grabber(GameObject parent)
- {
- prefab = Utils.staticVars.grabber;
- name = "grabber";
- this.parent = parent;
- gunObject = (GameObject)Network.Instantiate(prefab, parent.transform.position, Quaternion.identity, 0);
- gunObject.transform.parent = parent.transform;
- }
- public override void PrimaryFire()
- {
- if (grabbedObject == null)
- {
- RaycastHit rayCastHit;
- Physics.Raycast(parent.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 2f)), out rayCastHit);
- if (rayCastHit.collider.gameObject.tag == "Pickable")
- {
- grabbedObject = rayCastHit.collider.gameObject;
- grabbedObject.transform.parent = parent.transform;
- }
- else
- {
- grabbedObject = null;
- }
- }
- else
- {
- grabbedObject.transform.parent = null;
- grabbedObject = null;
- }
- }
- public override void SecondaryFire()
- {
- if (grabbedObject != null)
- {
- grabbedObject.transform.parent = null;
- grabbedObject = null;
- }
- }
- public override void Unequip()
- {
- //gunObject.renderer.enabled = false;
- isEnabled = false;
- grabbedObject.transform.parent = null;
- grabbedObject = null;
- }
- public override void Eqiup()
- {
- //gunObject.renderer.enabled = true;
- isEnabled = true;
- grabbedObject = null;
- }
- public override void OnUpdate()
- {
- if (grabbedObject != null)
- {
- grabbedObject.rigidbody.velocity = Vector3.zero;
- grabbedObject.rigidbody.angularVelocity = Vector3.zero;
- Vector3 inFrontOfCamera = parent.camera.ViewportToWorldPoint(new Vector3(0.5F, 0.5F, 2));
- grabbedObject.transform.position = inFrontOfCamera;
- grabbedObject.rigidbody.position = inFrontOfCamera;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement