Behavior choice complete
omg ça marche juste la défense il faut une reine mais en vrai c'est pas grave
This commit is contained in:
parent
0e815e1a05
commit
f52ac8863c
11 changed files with 1295 additions and 15 deletions
58
Assets/Scripts/ShopCanvas.cs
Normal file
58
Assets/Scripts/ShopCanvas.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class ShopCanvas : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera _camera;
|
||||
public Vector3 lastPosition;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
[SerializeField] private LayerMask behaviorLayer;
|
||||
|
||||
[SerializeField] private GameObject behaviorMenu;
|
||||
|
||||
public Vector3 MapPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, placementLayer))
|
||||
{
|
||||
// Get the hit point from the raycast
|
||||
Vector3 hitPoint = hit.point;
|
||||
|
||||
// Sample the closest valid position on the NavMesh
|
||||
NavMeshHit navMeshHit;
|
||||
if (NavMesh.SamplePosition(hitPoint, out navMeshHit, 1.0f, NavMesh.AllAreas))
|
||||
{
|
||||
lastPosition = navMeshHit.position; // Update lastPosition to the valid NavMesh position
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("No valid NavMesh position near the hit point.");
|
||||
}
|
||||
}
|
||||
|
||||
return lastPosition;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, behaviorLayer))
|
||||
{
|
||||
GameObject unite = hit.transform.GameObject();
|
||||
behaviorMenu.SetActive(true);
|
||||
behaviorMenu.GetComponent<BehaviorChoice>().chosenUnit = unite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue