What I'm trying to do is enabling the fist objects when I click trigger and disable the hand objects on my VR controllers and then when I release them, disable the fist objects and enable the hand objects. I get the error object reference not set an instance of an object. I thought initially it was a problem with my formatting but at this point I am confused, it seems like I have everything referenced IDK :/ :
using System.Collections;
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using UnityEditor;
using UnityEngine;
using UnityEngine.XR;
public class Hand : MonoBehaviour
{
private InputDevice targetDevice;
// Start is called before the first frame update
void Start()
{
GameObject.Find("RightFist").SetActive(false);
GameObject.Find("LeftFist").SetActive(false);
List<InputDevice> devices = new List<InputDevice>();
InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
foreach (var item in devices)
{
Debug.Log(item.name + item.characteristics);
}
if (devices.Count > 0)
{
targetDevice = devices[0];
}
}
// Update is called once per frame
void Update()
{
targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue);
if (triggerValue > 0.1f)
{
EnableFists();
DisableHands();
}
else
{
EnableHands();
DisableFists();
}
}
private static void EnableFists()
{
GameObject.Find("RightFist").SetActive(true);
GameObject.Find("LeftFist").SetActive(true);
}
private static void DisableFists()
{
GameObject.Find("RightFist").SetActive(false);
GameObject.Find("LeftFist").SetActive(false);
}
private static void EnableHands()
{
GameObject.Find("RightHand").SetActive(true);
GameObject.Find("LeftHand").SetActive(true);
}
private static void DisableHands()
{
GameObject.Find("RightHand").SetActive(false);
GameObject.Find("LeftHand").SetActive(false);
}
}