CreateManager.cs 1.99 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

public class CreateManager : MonoBehaviour
{

    public ARRaycastManager raycastMgr;
    public ARPlane _ARPlane;
    public GameObject placeObject;
    private List<ARRaycastHit> hits = new List<ARRaycastHit>();
    private List<GameObject> obj = new List<GameObject>();
    bool created;

    public bool gameoverTimerActivate;

    /// <summary>
    /// Game Over Script here
    /// </summary>

    private float deadTime;
    public GameObject gOverPanel;

    // Start is called before the first frame update
    void Start()
    {
        placeObject.SetActive(false);
        deadTime = 0;
        created = false;
        gOverPanel.SetActive(false);
        
    }

    // Update is called once per frame
    void Update()
    {
        if(created == false)
        {
            UpdateCenterObject();
        }
        if (placeObject.activeSelf == true) // 활성화 상태면
        {
            deadTime += Time.deltaTime; // 1초씩 타임 재기
        }

        checkDead();
    }

    void UpdateCenterObject()
    {
        Vector3 screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        raycastMgr.Raycast(screenCenter, hits, TrackableType.PlaneWithinPolygon);
        if (hits.Count > 0)
        {
            Pose placementPose = hits[0].pose;
            placeObject.SetActive(true);
            placeObject.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation);
            created = true;
        }

    }

    void checkDead()
    {

        if (gameoverTimerActivate)
        {
            if (deadTime >= 5f) // 타임이 10이 되면
            {
                Time.timeScale = 0; // 일시정지시키고
                gOverPanel.SetActive(true); // gameOver 패널을 활성화
                                            //GameOver 텍스트 출력
            }
        }

    }

}