add unlock system for tools
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class NoTool : Tool
|
||||
{
|
||||
public override void Use()
|
||||
{
|
||||
// Do nothin'
|
||||
}
|
||||
|
||||
public override void UseAlt()
|
||||
{
|
||||
// Do nothin'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15984e9d9e7f6074f97a69185e39ebb6
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user