using System.Collections; using System.Collections.Generic; using UnityEngine; public class useDevicesAtDistancePower : MonoBehaviour { [Header ("Main Settings")] [Space] public bool powerEnabled; public LayerMask layer; public List tagToCheck = new List (); public bool useInfiniteRaycastDistance = true; public float raycastDistance = 100; public bool ignoreDeviceToControlAtDistanceComponent; [Space] [Header ("Components")] [Space] public usingDevicesSystem usingDevicesManager; public Transform mainCameraTransform; public playerInputManager playerInput; public Collider playerCollider; public GameObject player; RaycastHit hit; GameObject currentDeviceToUse; public void activatePower () { if (!powerEnabled) { return; } float currentRaycastDistance = raycastDistance; if (useInfiniteRaycastDistance) { currentRaycastDistance = Mathf.Infinity; } if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward), out hit, currentRaycastDistance, layer)) { if (hit.collider.isTrigger && tagToCheck.Contains (hit.collider.tag)) { currentDeviceToUse = hit.collider.gameObject; if (!ignoreDeviceToControlAtDistanceComponent) { deviceToControlAtDistance currentDeviceToControlAtDistance = currentDeviceToUse.GetComponent (); if (currentDeviceToControlAtDistance != null) { if (!currentDeviceToControlAtDistance.isDeviceToControlEnabled ()) { return; } currentDeviceToUse = currentDeviceToControlAtDistance.getDeviceToControlGameObject (); } } electronicDevice currentElectronicDevice = currentDeviceToUse.GetComponent (); if (currentElectronicDevice != null) { currentElectronicDevice.checkTriggerInfo (playerCollider, true); usingDevicesManager.useCurrentDevice (currentDeviceToUse); usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse); } simpleSwitch currentSimpleSwitch = currentDeviceToUse.GetComponent (); if (currentSimpleSwitch != null) { usingDevicesManager.useCurrentDevice (currentDeviceToUse); usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse); } inventoryObject currentInventoryObject = currentDeviceToUse.GetComponent (); if (currentInventoryObject != null) { pickUpObject currentPickupObject = currentDeviceToUse.GetComponentInParent (); if (currentPickupObject != null) { currentPickupObject.checkTriggerInfo (playerCollider); usingDevicesManager.useCurrentDevice (currentDeviceToUse); usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse); } } } } } }