Hi. I made a game that includes holding objects and placing them into a cabinet. I have properly implemented the holding action and interaction system. However, I cannot combine these two. I want to place them in a specific location.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VHS;
public class PickingController : MonoBehaviour
{
[SerializeField] private Transform playerCameraTransform;
[SerializeField] private Transform objectGrabPointTransform;
[SerializeField] private LayerMask pickUpLayerMask;
private PickableObject pickableObject;
InteractableBase interactableBase;
public static bool canDrop;
private void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
if (pickableObject == null)
{
// Not carrying an object, try to grab
float pickUpDistance = 4f;
if (Physics.Raycast(playerCameraTransform.position, playerCameraTransform.forward, out RaycastHit raycastHit, pickUpDistance, pickUpLayerMask))
{
if (raycastHit.transform.TryGetComponent(out pickableObject))
{
pickableObject.PickUp(objectGrabPointTransform);
}
}
}
else
{
if(canDrop == true)
{
pickableObject.Drop();
pickableObject = null;
}
// Currently carrying something, drop
}
}
}
}
This is for interaction
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace VHS
{
public class DestroyInteractable : InteractableBase
{
PickableObject pickableObject;
public override void OnInteract()
{
base.OnInteract();
Debug.Log(gameObject);
PickableObject.objectGrabObject.transform.position = Vector3.zero;
}
}
}