GOOGLE ADS

jueves, 14 de abril de 2022

GetKeyDown envía múltiples salidas

específicamente, envía tantos resultados como objetos con el código que permite interactuar con ellos, incluso si presiono E cuando no estoy mirando nada. Quería hacer un sistema de inventario, pero esto hace que se interactúe con todos los objetos que tienen este código. Incluí todos los scripts que estoy usando para este sistema si eso puede ayudar. Realmente no sé lo que hice mal

el código del interactor:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
public class Interactable: MonoBehaviour
{
public LayerMask interactableLayerMask;
//ITEM VARIABLE
public Item item;
//PICK UP RADIUS
public float radius = 4f;
public void Interact()
{
Debug.Log("Interacted with " + transform.name);
PickUp();
}
//PICK UP INTERACTION
void PickUp()
{
Debug.Log("Picking up " + item.name);
bool wasPickedUp = Inventory.instance.Add(item);
if (wasPickedUp)
Destroy(gameObject);
}
//INTERACTION
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Added item -----------------------------------------");
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, radius))
{
Interactable interactable = hit.collider.GetComponent<Interactable>();
if (interactable!= null)
{
Interact();
}
} else
{
Debug.Log("Nothing");
}
}
}
}

el código de inventario:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory: MonoBehaviour
{
#region Singleton
public static Inventory instance;
void Awake()
{
if (instance!= null)
{
Debug.LogWarning("More than one instance of Inventory found!");
return;
}
instance = this;
}

No hay comentarios:

Publicar un comentario

Regla de Firestore para acceder a la generación de subcolección Permisos faltantes o insuficientes

Tengo problemas con las reglas de Firestore para permitir el acceso a algunos recursos en una subcolección. Tengo algunos requests document...