2024-07-04 17:22:55 +00:00
|
|
|
using System;
|
2024-07-01 03:11:10 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Dynamic;
|
2024-07-04 17:22:55 +00:00
|
|
|
using TMPro;
|
2024-07-01 03:11:10 +00:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class CharacterControl : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
Transform playerCamera;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
float seeDistance;
|
|
|
|
Interactable curretInteractable;
|
2024-07-03 12:03:50 +00:00
|
|
|
|
2024-07-02 02:42:09 +00:00
|
|
|
public GunPickable CurrentGun;
|
|
|
|
public GameObject holdingGun;
|
2024-07-01 03:11:10 +00:00
|
|
|
public RaycastHit hitInfo;
|
|
|
|
public static bool handsFull;
|
2024-07-02 02:42:09 +00:00
|
|
|
|
2024-07-01 03:11:10 +00:00
|
|
|
[SerializeField]
|
|
|
|
private GameObject hand;
|
2024-07-04 17:22:55 +00:00
|
|
|
public TextMeshProUGUI tooltips;
|
|
|
|
private Pickable newPickable;
|
|
|
|
public bool active;
|
2024-07-01 03:11:10 +00:00
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
if (active)
|
2024-07-01 03:11:10 +00:00
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (tooltips == null)
|
|
|
|
{
|
|
|
|
tooltips = GameObject.Find("toolTips").GetComponent<TextMeshProUGUI>();
|
|
|
|
}
|
|
|
|
Debug.Log(hitInfo.transform.name);
|
|
|
|
if (hitInfo.transform.TryGetComponent<Interactable>(out curretInteractable))
|
|
|
|
{
|
|
|
|
if (curretInteractable.tag == "door")
|
|
|
|
{
|
|
|
|
if (curretInteractable.name=="doorSlide"&&!GameManager.instance.petrolCollected
|
|
|
|
&& !GameManager.instance.gotGenerator)
|
|
|
|
{
|
|
|
|
tooltips.text = "get the Generator and Petrol to power the ship";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltips.text = "Press [e] to open door";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (curretInteractable.name == "petrol")
|
|
|
|
{
|
|
|
|
if (!GameManager.instance.petrolCollected)
|
|
|
|
{
|
|
|
|
tooltips.text = "Press [e] to pump petrol";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltips.text = "petrol Collected";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (curretInteractable.TryGetComponent<Pickable>(out newPickable))
|
|
|
|
{
|
|
|
|
if (handsFull)
|
|
|
|
{
|
|
|
|
tooltips.text = "hands are full drop item using [g]";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltips.text = "Press [e] to Pick up";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (curretInteractable.tag == "collectable")
|
|
|
|
{
|
|
|
|
tooltips.text = "press [e] to collect";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curretInteractable = null;
|
|
|
|
CurrentGun = null;
|
|
|
|
tooltips.text = "";
|
|
|
|
}
|
|
|
|
}
|
2024-07-01 03:11:10 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
curretInteractable = null;
|
2024-07-04 17:22:55 +00:00
|
|
|
CurrentGun = null;
|
|
|
|
|
|
|
|
tooltips.text = "";
|
2024-07-01 03:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnInteract()
|
|
|
|
{
|
|
|
|
if (curretInteractable != null)
|
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
if (!handsFull && curretInteractable.TryGetComponent<GunPickable>(out CurrentGun))
|
2024-07-02 02:42:09 +00:00
|
|
|
{
|
|
|
|
holdingGun = CurrentGun.gameObject;
|
2024-07-04 17:22:55 +00:00
|
|
|
handsFull = true;
|
|
|
|
curretInteractable.Interact();
|
|
|
|
}
|
|
|
|
else if (!curretInteractable.TryGetComponent<GunPickable>(out CurrentGun))
|
|
|
|
{
|
|
|
|
curretInteractable.Interact();
|
2024-07-02 02:42:09 +00:00
|
|
|
}
|
2024-07-01 03:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnShoot()
|
|
|
|
{
|
|
|
|
Debug.Log("Shoot");
|
2024-07-04 17:22:55 +00:00
|
|
|
if (holdingGun != null)
|
2024-07-01 03:11:10 +00:00
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
holdingGun.GetComponent<Gun>().Shoot();
|
2024-07-01 03:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnReload()
|
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
if (holdingGun != null)
|
2024-07-01 03:11:10 +00:00
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
holdingGun.GetComponent<Gun>().Reload();
|
2024-07-01 03:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDrop()
|
|
|
|
{
|
2024-07-04 17:22:55 +00:00
|
|
|
holdingGun.transform.GetComponent<Pickable>().Drop();
|
|
|
|
holdingGun = null;
|
|
|
|
handsFull = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPause()
|
|
|
|
{
|
|
|
|
GameManager.instance.Pause();
|
2024-07-01 03:11:10 +00:00
|
|
|
}
|
|
|
|
}
|