PortalDemo.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Imagine.WebAR;
  4. using UnityEngine;
  5. namespace Imagine.WebAR.Demo{
  6. public class PortalDemo : MonoBehaviour
  7. {
  8. [SerializeField] GameObject portalMaskRealSide, portalMaskVirtualSide;
  9. [SerializeField] Transform doorTransform, camTransform;
  10. public float lastZ;
  11. void Start(){
  12. var camTransform = FindObjectOfType<ARCamera>().transform;
  13. lastZ = doorTransform.InverseTransformPoint(camTransform.position).z;
  14. }
  15. void Update()
  16. {
  17. var z = doorTransform.InverseTransformPoint(camTransform.position).z;
  18. var thresh = 0.02f;
  19. if(lastZ > thresh && z < thresh){
  20. portalMaskRealSide.SetActive(false);
  21. portalMaskVirtualSide.SetActive(true);
  22. }
  23. else if(lastZ < -thresh && z > -thresh){
  24. portalMaskRealSide.SetActive(true);
  25. portalMaskVirtualSide.SetActive(false);
  26. }
  27. lastZ = z;
  28. }
  29. }
  30. }