Commit 36a5a80b authored by 18손재민's avatar 18손재민

머지함. 플레이어 이동 중 다른 플레이어 선택 시 발생하는 오류 수정함. 현재 bullet과 관련해서 호출하는 오브젝트가 없어 오류가 있는지 확인할 수가 없음. 나중에 확인할 것

parent ec3bda99
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6aaeac95275fd9142a4a0f13fc71837e guid: ac3371a68e3523b4f905d8bfc52f6da4
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6aaeac95275fd9142a4a0f13fc71837e guid: 04b8bdcf5e4a6f041bd8f30be7c4b604
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
......
fileFormatVersion: 2
guid: a32ca40f7f255ea47ac7ee9d558755ce
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -5,7 +5,7 @@ using UnityEngine.AI; ...@@ -5,7 +5,7 @@ using UnityEngine.AI;
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
Coroutine playerArivalCheck; Coroutine playerArrivalCheck;
public IEnumerator SetCurrentPlayer() public IEnumerator SetCurrentPlayer()
{ {
...@@ -23,22 +23,23 @@ public class Player : MonoBehaviour ...@@ -23,22 +23,23 @@ public class Player : MonoBehaviour
{ {
NavMeshAgent agent = GetComponent<NavMeshAgent>(); NavMeshAgent agent = GetComponent<NavMeshAgent>();
NavMeshPath path = new NavMeshPath(); NavMeshPath path = new NavMeshPath();
if(playerArivalCheck != null) if(playerArrivalCheck != null)
StopCoroutine(playerArivalCheck); StopCoroutine(playerArrivalCheck);
playerArivalCheck = StartCoroutine(CheckIfPlayerArrived(destination)); PlayerController.inst.isPlayerMoving = true;
agent.CalculatePath(destination, path); playerArrivalCheck = StartCoroutine(CheckIfPlayerArrived(destination));
agent.CalculatePath(destination, path);
if(path.status == NavMeshPathStatus.PathComplete) if(path.status == NavMeshPathStatus.PathComplete)
GetComponent<NavMeshAgent>().SetDestination(destination); GetComponent<NavMeshAgent>().SetDestination(destination);
else else
Debug.Log("Destination is not reachable."); Debug.Log("Destination is not reachable.");
} }
IEnumerator CheckIfPlayerArrived(Vector3 destination) IEnumerator CheckIfPlayerArrived(Vector3 destination)
{ {
while(transform.position.x != destination.x || transform.position.z != destination.z) while (Mathf.Abs(transform.position.x - destination.x) > 0.001f || Mathf.Abs(transform.position.z - destination.z) > 0.001f)
{ {
yield return null; yield return null;
PlayerController.inst.isPlayerMoving = true; }
} transform.position = new Vector3(destination.x, transform.position.y, destination.z);
PlayerController.inst.isPlayerMoving = false; PlayerController.inst.isPlayerMoving = false;
} }
// Start is called before the first frame update // Start is called before the first frame update
......
...@@ -38,29 +38,29 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -38,29 +38,29 @@ public class PlayerController : SingletonBehaviour<PlayerController>
prePos = MapPos; prePos = MapPos;
} }
if (Input.GetMouseButtonDown(0) && !isPlayerMoving) if (Input.GetMouseButtonDown(0) && !isPlayerMoving)
{ {
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; RaycastHit hit;
if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("Player")) if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("Player"))
{ {
if(currentPlayer != null) if (currentPlayer != null)
currentPlayer.ResetCurrentPlayer(); currentPlayer.ResetCurrentPlayer();
currentPlayer = hit.transform.gameObject.GetComponent<Player>(); currentPlayer = hit.transform.gameObject.GetComponent<Player>();
StartCoroutine(currentPlayer.SetCurrentPlayer()); StartCoroutine(currentPlayer.SetCurrentPlayer());
Debug.Log(hit.collider.gameObject.tag); Debug.Log(hit.collider.gameObject.tag);
} }
else if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor")) else if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor"))
{ {
if (currentPlayer != null) if (currentPlayer != null)
currentPlayer.MovePlayer(hit.collider.gameObject.transform.position); 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)
{ {
if (currentPlayer != null) if (currentPlayer != null)
currentPlayer.ResetCurrentPlayer(); currentPlayer.ResetCurrentPlayer();
} }
} }
} }
} }
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