Physics2D.Raycast
https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
Debug.DrawRay
https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html
if(PV == null) {
return;
}
if(PV != null) {
Debug.DrawRay(new Vector2(NetworkManager.instance.player.transform.position.x, NetworkManager.instance.player.transform.position.y - 17), Vector2.down * 10f, Color.red);
RaycastHit2D rayHit = Physics2D.Raycast(new Vector2(NetworkManager.instance.player.transform.position.x, NetworkManager.instance.player.transform.position.y - 17), Vector2.down, 10f, LayerMask.GetMask("object"));
if(rayHit.collider != null) {
if(rayHit.collider.gameObject.tag == "Player")
{
// Debug.Log(rayHit.collider.gameObject);
// Debug.Log(rayHit.collider.gameObject.GetComponent<BoxCollider2D>().bounds);
Debug.Log(rayHit.collider.gameObject.GetComponent<SpriteRenderer>().sortingOrder);
this.GetComponent<SpriteRenderer>().sortingOrder = rayHit.collider.gameObject.GetComponent<SpriteRenderer>().sortingOrder - 1;
}
} else {
this.GetComponent<SpriteRenderer>().sortingOrder = 0;
}
}
Debug.DrawRay로 먼저 그리고
raycast를 선언하면 보기 쉽다
언젠가는 볼 참고 사이트 ..