Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Portal : MonoBehaviour
- {
- private const string PLAYER_TAG = "Player";
- [SerializeField] Transform otherPortal;
- [SerializeField] private Camera myCamera;
- public Camera GetMyCamera()
- {
- return myCamera;
- }
- [SerializeField] private Transform myRenderPlane;
- [SerializeField] private Transform myCollider;
- // public Transform GetMyCollider() => myCollider;
- public Transform GetMyCollider()
- {
- return myCollider;
- }
- [SerializeField] Material material;
- private GameObject player;
- private PortalCamera portalCamera;
- private PortalTeleport portalTeleport;
- private void Awake()
- {
- portalCamera = myCamera.GetComponent<PortalCamera>();
- portalTeleport = myCollider.GetComponent<PortalTeleport>();
- player = GameObject.FindGameObjectWithTag(PLAYER_TAG);
- //// jeżeli kamera jest jako 1 dziecko obiektu gracza
- //portalCamera.playerCamera = player.transform.GetChild(0);
- //// wykorzystujemy główną kamera - oznaczoną tagiem "MainCamera"
- //portalCamera.playerCamera = Camera.main.transform;
- portalCamera.playerCamera = player.GetComponentInChildren<Camera>().transform;
- portalCamera.otherPortal = otherPortal.transform;
- portalCamera.portal = transform;
- portalTeleport.player = player.transform;
- portalTeleport.receiver = otherPortal.GetComponent<Portal>().GetMyCollider();
- myRenderPlane.GetComponent<Renderer>().material = Instantiate(material);
- if (myCamera.targetTexture != null)
- {
- myCamera.targetTexture.Release();
- }
- myCamera.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
- float myAngle = transform.localEulerAngles.y % 360;
- portalCamera.SetMyAngle(myAngle);
- }
- private void Start()
- {
- myRenderPlane.GetComponent<Renderer>().material.mainTexture =
- otherPortal.GetComponent<Portal>().GetMyCamera().targetTexture;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement