using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickup : MonoBehaviour
{
public Camera cam;
public Transform hand;
Collider pickable2;
int pickUpAbleGameobjectLayer = 8;
public bool isholding;
public float yeetforce;
public float distance;
public void Update()
{
if (Input.GetKeyDown(KeyCode.E) && !isholding)
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, distance))
{
Collider pickupable = hit.collider.GetComponent<Collider>();
if(hit.collider.GetComponent<CharacterController>()) { return; }
if (pickupable.gameObject.layer == pickUpAbleGameobjectLayer)
{
pickupable.GetComponent<Rigidbody>().isKinematic = true;
pickupable.transform.parent = hand.transform;
pickupable.transform.position = hand.transform.position;
pickupable.transform.rotation = transform.rotation;
Debug.Log("yoot");
pickable2 = pickupable;
isholding = true;
if (pickupable.gameObject.tag != "Tool") { return; }
**pickupable.transform.rotation = Quaternion.Euler(0, 90, 0);** //this is the part im having troubles
}
}
}
if (Input.GetKeyDown(KeyCode.Q) && isholding)
{
pickable2.transform.SetParent(null);
pickable2.GetComponent<Rigidbody>().isKinematic = false;
isholding = false;
pickable2.GetComponent<Rigidbody>().AddForce(cam.transform.forward * yeetforce, ForceMode.Impulse);
Debug.Log("YEET");
}
}
}