87 lines
1.9 KiB
C#
87 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class CharacterControl : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
Transform playerCamera;
|
|
|
|
[SerializeField]
|
|
float seeDistance;
|
|
Interactable curretInteractable;
|
|
|
|
public GunPickable CurrentGun;
|
|
public GameObject holdingGun;
|
|
public RaycastHit hitInfo;
|
|
public static bool handsFull;
|
|
|
|
[SerializeField]
|
|
private GameObject hand;
|
|
|
|
void Update()
|
|
{
|
|
bool Raycast = Physics.Raycast(
|
|
playerCamera.position,
|
|
playerCamera.TransformDirection(Vector3.forward),
|
|
out hitInfo,
|
|
seeDistance
|
|
);
|
|
Debug.DrawRay(
|
|
playerCamera.position,
|
|
playerCamera.TransformDirection(Vector3.forward) * seeDistance,
|
|
Color.green
|
|
);
|
|
if (Raycast)
|
|
{
|
|
Debug.Log(hitInfo.transform.name);
|
|
if (hitInfo.transform.TryGetComponent<Interactable>(out curretInteractable)) { }
|
|
else
|
|
{
|
|
curretInteractable = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
curretInteractable = null;
|
|
}
|
|
}
|
|
|
|
void OnInteract()
|
|
{
|
|
if (curretInteractable != null)
|
|
{
|
|
curretInteractable.Interact();
|
|
if (curretInteractable.TryGetComponent<GunPickable>(out CurrentGun))
|
|
{
|
|
holdingGun = CurrentGun.gameObject;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void OnShoot()
|
|
{
|
|
Debug.Log("Shoot");
|
|
if (CurrentGun != null)
|
|
{
|
|
CurrentGun.GetComponent<Gun>().Shoot();
|
|
}
|
|
}
|
|
|
|
void OnReload()
|
|
{
|
|
if (CurrentGun != null)
|
|
{
|
|
CurrentGun.GetComponent<Gun>().Reload();
|
|
}
|
|
}
|
|
|
|
void OnDrop()
|
|
{
|
|
CurrentGun.transform.GetComponent<Pickable>().Drop();
|
|
}
|
|
}
|