add unlock system for tools

This commit is contained in:
2026-06-29 22:15:59 -05:00
parent 9dfcee6159
commit fc0bcf0201
12 changed files with 513 additions and 65 deletions
+14
View File
@@ -0,0 +1,14 @@
using UnityEngine;
public class NoTool : Tool
{
public override void Use()
{
// Do nothin'
}
public override void UseAlt()
{
// Do nothin'
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 15984e9d9e7f6074f97a69185e39ebb6
+41 -19
View File
@@ -20,7 +20,6 @@ private void Update()
{
if (GameManager.Instance.PlayerController != null)
{
SetGroundPlane();
DrawTargetProjection();
}
}
@@ -43,28 +42,51 @@ private void DrawTargetProjection()
targetProjection = GetComponentInChildren<DecalProjector>();
}
Transform player = GameManager.Instance.PlayerController.DougBody.transform;
Transform camera = GameManager.Instance.PlayerController.cameraController.MainCamera.transform;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (handGroundPlane.Raycast(ray, out var distance))
Vector3 targetPoint;
// First try real world geometry
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
{
Vector3 hitPoint = ray.GetPoint(distance);
float distanceFromPoint = Vector3.Distance(hitPoint, transform.position);
if (distanceFromPoint > range)
{
Vector3 directionTowardMouse = (hitPoint - transform.position).normalized;
targetProjection.transform.position = new Vector3(transform.position.x, hitPoint.y, transform.position.z);
targetProjection.transform.position += directionTowardMouse * range;
throwForce = range;
}
else
{
targetProjection.gameObject.SetActive(true);
targetProjection.transform.position = hitPoint;
throwForce = distanceFromPoint;
}
targetPoint = hit.point;
}
else
{
// Fallback plane if nothing hit
Plane plane = new Plane(Vector3.up, player.position);
if (!plane.Raycast(ray, out float distance))
return;
targetPoint = ray.GetPoint(distance);
}
// Flatten relative to player
Vector3 offset = targetPoint - player.position;
offset.y = 0f;
// Clamp range
offset = Vector3.ClampMagnitude(offset, range);
throwForce = offset.magnitude;
// Final position
Vector3 finalPosition = player.position + offset;
// Snap back to ground
if (Physics.Raycast(
finalPosition + Vector3.up * 10f,
Vector3.down,
out RaycastHit groundHit,
50f))
{
finalPosition = groundHit.point;
}
targetProjection.transform.position = finalPosition;
}
public override void Use()
+11 -1
View File
@@ -2,8 +2,8 @@
public abstract class Tool : MonoBehaviour
{
[Header("Base Tool Parameters")]
public ToolEnum ToolType = ToolEnum.None;
public float useTimeSec;
public float altUseTimeSec;
public bool inUse;
@@ -14,3 +14,13 @@ public abstract class Tool : MonoBehaviour
// secondary (right click)
public abstract void UseAlt();
}
public enum ToolEnum
{
None,
Shovel,
Flashlight,
GrappleGun,
Ballgun,
ThrowableHand
}