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

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

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