Closed RotX18 closed 2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IPickable
{
enum Controller {
LTouch,
RTouch,
None
}
bool Grabbed{
get;
set;
}
Controller CurrentController {
get;
set;
}
void OnRelease();
}
Description:
private void Update() {
//LEFT HAND
if(OVRInput.Get(OVRInput.RawButton.LHandTrigger)) {
//if the left hand trigger is pressed more than half, raycast in the +X axis of the controller
_doLeftRaycast = true;
if(_leftHandObj != null) {
//if there is an object below the left hand, set the obj's position to just below the hand
_leftHandObj.transform.SetParent(leftAnchor.transform);
_leftHandObj.transform.position = leftAnchor.transform.position;
//setting the vars if the object implements IPickable
if(_leftHandObj.GetComponent<IPickable>() != null){
_leftHandObj.GetComponent<IPickable>().Grabbed = true;
_leftHandObj.GetComponent<IPickable>().CurrentController = IPickable.Controller.LTouch;
}
}
}
else {
//When the left hand trigger is let go, reset the vars
_doLeftRaycast = false;
try {
if(_leftHandObj.GetComponent<IPickable>() != null) {
_leftHandObj.GetComponent<IPickable>().Grabbed = false;
_leftHandObj.GetComponent<IPickable>().CurrentController = IPickable.Controller.None;
_leftHandObj.GetComponent<IPickable>().OnRelease();
}
_leftHandObj.transform.parent = null;
_leftHandObj = null;
}
catch(System.NullReferenceException) {
}
}
}
Edits:
Objective: An interface that allows for a more streamlined way of interacting with grabbable objects within the scene