해당 폴리곤 내에서만 카메라 활동 영역 제한 코드를 만드는데
코드가 대략 이렇습니다
[SerializeField] PolygonCollider2D mapBoundry;
CinemachineConfiner2D confiner;
[SerializeField] Direction direction;
[SerializeField] float additivePos = 2f;
enum Direction {Up, Down, Left, Right }
private void Awake()
{
confiner = FindObjectOfType<CinemachineConfiner2D>(); <<이 부분이 안된다고 뜸
그래서 이 부분을 confiner = Object.FindAnyObjectByType<CinemachineConfiner2D>(); 로 바꾸면
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.CompareTag("Player"))
{
confiner.m_BoundingShape2D = mapBoundry; << 바꿀 경우 여기가 오류가 뜸
UpdatePlayerPosition(collision.gameObject);
}
}
private void UpdatePlayerPosition(GameObject player)
{
Vector3 newPos = player.transform.position;
switch (direction)
{
case Direction.Up:
newPos.y += additivePos;
break;
case Direction.Down:
newPos.y -= additivePos;
break;
case Direction.Left:
newPos.x += additivePos;
break;
case Direction.Right:
newPos.x -= additivePos;
break;
}
player.transform.position = newPos;
}
최신 버전에서 이 코드를 기능하게 할려면 어떻게 해야 하나요?
오류를 읽어보면 Obsolete라잖음 오류가 아니라 경고임 FindFirstObjectByType인가 뭔가로 완전히 대체됨 비슷한 부류의 함수 있으니 찾아보면됨