Files
Robii Aragon fd87a6ffd5 add ckg
plantilla base para movimiento básico
2026-02-05 05:07:55 -08:00

98 lines
3.3 KiB
C#

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<string> tagToCheck = new List<string> ();
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<deviceToControlAtDistance> ();
if (currentDeviceToControlAtDistance != null) {
if (!currentDeviceToControlAtDistance.isDeviceToControlEnabled ()) {
return;
}
currentDeviceToUse = currentDeviceToControlAtDistance.getDeviceToControlGameObject ();
}
}
electronicDevice currentElectronicDevice = currentDeviceToUse.GetComponent<electronicDevice> ();
if (currentElectronicDevice != null) {
currentElectronicDevice.checkTriggerInfo (playerCollider, true);
usingDevicesManager.useCurrentDevice (currentDeviceToUse);
usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse);
}
simpleSwitch currentSimpleSwitch = currentDeviceToUse.GetComponent<simpleSwitch> ();
if (currentSimpleSwitch != null) {
usingDevicesManager.useCurrentDevice (currentDeviceToUse);
usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse);
}
inventoryObject currentInventoryObject = currentDeviceToUse.GetComponent<inventoryObject> ();
if (currentInventoryObject != null) {
pickUpObject currentPickupObject = currentDeviceToUse.GetComponentInParent<pickUpObject> ();
if (currentPickupObject != null) {
currentPickupObject.checkTriggerInfo (playerCollider);
usingDevicesManager.useCurrentDevice (currentDeviceToUse);
usingDevicesManager.setObjectToRemoveAferStopUse (currentDeviceToUse);
}
}
}
}
}
}