fix navmesh no find
cringe unity instantiate C# + java cringe operator overloading making things not clea renough
This commit is contained in:
parent
f8c859ed96
commit
769264c79b
4 changed files with 25 additions and 7 deletions
|
@ -3924,7 +3924,7 @@ PrefabInstance:
|
|||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6208992634893184319, guid: e2eadb5c4fdf45ea995b4da7c9110275, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: -0.091646194
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6208992634893184319, guid: e2eadb5c4fdf45ea995b4da7c9110275, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
|
@ -29482,7 +29482,7 @@ Transform:
|
|||
m_GameObject: {fileID: 2002548185}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -46.1, y: 4.1, z: 56.2}
|
||||
m_LocalPosition: {x: -46.1, y: 2.81, z: 56.2}
|
||||
m_LocalScale: {x: 2.3030813, y: 2.3030813, z: 2.3030813}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
|
|
|
@ -837,6 +837,10 @@ PrefabInstance:
|
|||
propertyPath: m_Name
|
||||
value: ZombieA
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4976282506935113607, guid: a0750dd4706e5480da2ad597b62d8531, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5387376515481739062, guid: a0750dd4706e5480da2ad597b62d8531, type: 3}
|
||||
propertyPath: m_AnchorMax.x
|
||||
value: 0
|
||||
|
|
|
@ -43,8 +43,7 @@ public class UnitButton : MonoBehaviour
|
|||
void PlaceUnit()
|
||||
{
|
||||
Vector3 mousePos = unitPlacement.MapPosition();
|
||||
GameObject go = Instantiate(unitPrefab);
|
||||
go.transform.position = mousePos;
|
||||
GameObject go = Instantiate(unitPrefab, mousePos, Quaternion.identity);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class UnitPlacement : MonoBehaviour
|
||||
{
|
||||
|
@ -12,10 +13,24 @@ public class UnitPlacement : MonoBehaviour
|
|||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray,out hit, 100, placementLayer))
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, placementLayer))
|
||||
{
|
||||
lastPosition = hit.point;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue