Commit 6f6cde67 authored by 18손재민's avatar 18손재민

원하는 플레이어만 선택해서 이동가능

parent 0cb1a22a
...@@ -14,6 +14,7 @@ GameObject: ...@@ -14,6 +14,7 @@ GameObject:
- component: {fileID: 8862060874303168222} - component: {fileID: 8862060874303168222}
- component: {fileID: 857076055737488221} - component: {fileID: 857076055737488221}
- component: {fileID: 8862060874303168218} - component: {fileID: 8862060874303168218}
- component: {fileID: 5785432140392015245}
m_Layer: 8 m_Layer: 8
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Player
...@@ -29,7 +30,7 @@ Transform: ...@@ -29,7 +30,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8862060874303168220} m_GameObject: {fileID: 8862060874303168220}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.5, z: 3.18} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
...@@ -113,7 +114,7 @@ NavMeshAgent: ...@@ -113,7 +114,7 @@ NavMeshAgent:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8862060874303168220} m_GameObject: {fileID: 8862060874303168220}
m_Enabled: 1 m_Enabled: 0
m_AgentTypeID: 0 m_AgentTypeID: 0
m_Radius: 0.5 m_Radius: 0.5
m_Speed: 5 m_Speed: 5
...@@ -128,3 +129,19 @@ NavMeshAgent: ...@@ -128,3 +129,19 @@ NavMeshAgent:
m_BaseOffset: 1 m_BaseOffset: 1
m_WalkableMask: 4294967295 m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4 m_ObstacleAvoidanceType: 4
--- !u!208 &5785432140392015245
NavMeshObstacle:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8862060874303168220}
m_Enabled: 1
serializedVersion: 3
m_Shape: 1
m_Extents: {x: 0.5, y: 1, z: 0.5}
m_MoveThreshold: 0.1
m_Carve: 1
m_CarveOnlyStationary: 0
m_Center: {x: 0, y: 0, z: 0}
m_TimeToStationary: 0.5
...@@ -490,6 +490,11 @@ PrefabInstance: ...@@ -490,6 +490,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1444571407667829093, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f, type: 3}
--- !u!1001 &5089720519379341084 --- !u!1001 &5089720519379341084
...@@ -633,6 +638,12 @@ PrefabInstance: ...@@ -633,6 +638,12 @@ PrefabInstance:
propertyPath: surface propertyPath: surface
value: value:
objectReference: {fileID: 2102809461} objectReference: {fileID: 2102809461}
- target: {fileID: 3268100033343711389, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: stage.Array.data[0]
value:
objectReference: {fileID: 2597539376576235671, guid: bec0ce48aa2c7d14abcf504346360066,
type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 11285456de5f1854d947bea83275646f, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 11285456de5f1854d947bea83275646f, type: 3}
--- !u!1001 &7277015660625800392 --- !u!1001 &7277015660625800392
......
...@@ -199,6 +199,22 @@ public class Map : MonoBehaviour ...@@ -199,6 +199,22 @@ public class Map : MonoBehaviour
Debug.Log("Wall doesn't exists between : " + floor1.mapPos + ", " + floor2.mapPos); Debug.Log("Wall doesn't exists between : " + floor1.mapPos + ", " + floor2.mapPos);
} }
private void LoadObjects()
{
floorGrid = new Dictionary<Vector2Int, Floor>();
wallGrid = new Dictionary<Vector2, Wall>();
for (int i = 0; i < floors.transform.childCount; i++)
{
Floor floor = floors.transform.GetChild(i).GetComponent<Floor>();
floorGrid.Add(floor.mapPos, floor);
}
for (int i = 0; i < walls.transform.childCount; i++)
{
Wall wall = walls.transform.GetChild(i).GetComponent<Wall>();
wallGrid.Add(wall.mapPos, wall);
}
}
public void InitiateMap() public void InitiateMap()
{ {
floorGrid = new Dictionary<Vector2Int, Floor>(); floorGrid = new Dictionary<Vector2Int, Floor>();
...@@ -208,7 +224,7 @@ public class Map : MonoBehaviour ...@@ -208,7 +224,7 @@ public class Map : MonoBehaviour
private void Awake() private void Awake()
{ {
LoadObjects();
} }
// Start is called before the first frame update // Start is called before the first frame update
......
...@@ -23,7 +23,7 @@ public class MapManager : SingletonBehaviour<MapManager> ...@@ -23,7 +23,7 @@ public class MapManager : SingletonBehaviour<MapManager>
currentMap.transform.position = new Vector3(0, 0, 0); currentMap.transform.position = new Vector3(0, 0, 0);
surface.BuildNavMesh(); surface.BuildNavMesh();
for (int i = 0; i < currentMap.startFloors.Count; i++) for (int i = 0; i < currentMap.startFloors.Count; i++)
players.Add(Instantiate(player, currentMap.startFloors[i].transform.position + new Vector3(0, 1.5f, 0), Quaternion.identity)); players.Add(Instantiate(player, currentMap.startFloors[i].transform.position + new Vector3(0, 1.15f, 0), Quaternion.identity));
} }
public IEnumerator Rebaker() public IEnumerator Rebaker()
{ {
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AI;
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
public void SetCurrentPlayer() Coroutine playerArivalCheck;
public IEnumerator SetCurrentPlayer()
{ {
transform.localScale = new Vector3(1, 2, 1); GetComponent<NavMeshObstacle>().enabled = false;
yield return null;
GetComponent<NavMeshAgent>().enabled = true;
} }
public void ResetCurrentPlayer() public void ResetCurrentPlayer()
{ {
transform.localScale = new Vector3(1, 1, 1); GetComponent<NavMeshAgent>().enabled = false;
GetComponent<NavMeshObstacle>().enabled = true;
PlayerController.inst.currentPlayer = null; PlayerController.inst.currentPlayer = null;
} }
public void MovePlayer() public void MovePlayer(Vector3 destination)
{ {
NavMeshAgent agent = GetComponent<NavMeshAgent>();
NavMeshPath path = new NavMeshPath();
if(playerArivalCheck != null)
StopCoroutine(playerArivalCheck);
playerArivalCheck = StartCoroutine(CheckIfPlayerArrived(destination));
agent.CalculatePath(destination, path);
if(path.status == NavMeshPathStatus.PathComplete)
GetComponent<NavMeshAgent>().SetDestination(destination);
else
Debug.Log("Destination is not reachable.");
}
IEnumerator CheckIfPlayerArrived(Vector3 destination)
{
while(transform.position.x != destination.x || transform.position.z != destination.z)
{
yield return null;
PlayerController.inst.isPlayerMoving = true;
}
PlayerController.inst.isPlayerMoving = false;
} }
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
} }
// Update is called once per frame // Update is called once per frame
......
...@@ -6,6 +6,7 @@ using UnityEngine.AI; ...@@ -6,6 +6,7 @@ using UnityEngine.AI;
public class PlayerController : SingletonBehaviour<PlayerController> public class PlayerController : SingletonBehaviour<PlayerController>
{ {
public Player currentPlayer; public Player currentPlayer;
public bool isPlayerMoving;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -16,7 +17,7 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -16,7 +17,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0) && !isPlayerMoving)
{ {
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; RaycastHit hit;
...@@ -25,7 +26,13 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -25,7 +26,13 @@ public class PlayerController : SingletonBehaviour<PlayerController>
if(currentPlayer != null) if(currentPlayer != null)
currentPlayer.ResetCurrentPlayer(); currentPlayer.ResetCurrentPlayer();
currentPlayer = hit.transform.gameObject.GetComponent<Player>(); currentPlayer = hit.transform.gameObject.GetComponent<Player>();
currentPlayer.SetCurrentPlayer(); StartCoroutine(currentPlayer.SetCurrentPlayer());
Debug.Log(hit.collider.gameObject.tag);
}
else if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor"))
{
if (currentPlayer != null)
currentPlayer.MovePlayer(hit.collider.gameObject.transform.position);
Debug.Log(hit.collider.gameObject.tag); Debug.Log(hit.collider.gameObject.tag);
} }
else if(hit.collider == null) else if(hit.collider == null)
...@@ -33,12 +40,6 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -33,12 +40,6 @@ public class PlayerController : SingletonBehaviour<PlayerController>
if (currentPlayer != null) if (currentPlayer != null)
currentPlayer.ResetCurrentPlayer(); currentPlayer.ResetCurrentPlayer();
} }
/*if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor"))
{
GetComponent<NavMeshAgent>().SetDestination(hit.collider.gameObject.transform.position);
Debug.Log(hit.collider.gameObject.GetComponent<Floor>().mapPos);
Debug.Log(hit.collider.gameObject.tag);
}*/
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment