아카이브

포탈 텔레포트 본문

3D 콘텐츠 제작

포탈 텔레포트

timbercat 2023. 9. 25. 15:20

플레이어가 포탈에 충돌할 경우 생성될 위치를 지정한다

포탈에 너무 가깝게 있으면 오류날 수 있으니 적당하게 떨어트려 놓음

Player에 PortalManager 스크립트 추가

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class portalManager : MonoBehaviour
{
    public Transform APos;
    public Transform BPos;

    private void OnTriggerEnter(Collider col)
    {
        if (col.CompareTag("Portal A"))
        {
            CharacterController cc = GetComponent<CharacterController>();

            cc.enabled = false;
            transform.position = BPos.transform.position;
            transform.rotation = new Quaternion(transform.rotation.x, BPos.rotation.y, transform.rotation.z, transform.rotation.w);

            cc.enabled = true;
        }
        

        if (col.CompareTag("Portal B"))
        {
            CharacterController cc = GetComponent<CharacterController>();

            cc.enabled = false;
            transform.position = APos.transform.position;
            transform.rotation = new Quaternion(transform.rotation.x, APos.rotation.y, transform.rotation.z, transform.rotation.w);

            cc.enabled = true;
        }

    }
}

포지션 설정, 포탈에 콜라이더 넣고 isTrigger 체크

 

'3D 콘텐츠 제작' 카테고리의 다른 글

3D 프로젝트 발표  (0) 2023.10.12
플레이어 이동  (0) 2023.09.25
포탈 만들기  (0) 2023.09.25
3D 프로젝트로 제작할 게임  (0) 2023.09.22