[GVR] 게이지만들고 순간이동하기

Unity3D 2021. 7. 30. 14:53
반응형

 

UI의 RaycastTarget꺼주자 

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

public class VRCircle : MonoBehaviour
{
    public Image imgCircle;

    public float totalTime = 2.0f;
    bool gvrStatus;
    float gvrTimer;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    private void Update()
    {
        if (this.gvrStatus)
        {
            this.gvrTimer += Time.deltaTime;
            var amount = gvrTimer / totalTime;
            //Debug.Log(amount);
            this.imgCircle.fillAmount = amount;
        }
    }

    public void GVROn() {
        this.gvrStatus = true;
        Debug.Log("on");
    }
    public void GVROff()
    {
        this.gvrStatus = false;
        Debug.Log("off");
        this.gvrTimer = 0;
        this.imgCircle.fillAmount = 0;
    }
}

 

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

public class VRCircle : MonoBehaviour
{
    public Image imgCircle;
    public Transform teleportPos;

    public float totalTime = 2.0f;
    bool gvrStatus;
    float gvrTimer;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    private void Update()
    {
        if (this.gvrStatus)
        {
            this.gvrTimer += Time.deltaTime;
            var amount = gvrTimer / totalTime;
            //Debug.Log(amount);
            this.imgCircle.fillAmount = amount;
        }

        RaycastHit hit;
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.5f));

        Debug.DrawRay(ray.origin, ray.direction * 80, Color.yellow);

        if (Physics.Raycast(ray, out hit, 80))
        {

            Debug.Log(hit + " , " + this.imgCircle.fillAmount);

            if (this.imgCircle.fillAmount == 1 && hit.transform.CompareTag("Teleport"))
            {
                this.transform.position = this.teleportPos.position;
                this.GVROff();
            }
        }

    }

    public void GVROn() {
        this.gvrStatus = true;
        Debug.Log("on");
    }
    public void GVROff()
    {
        this.gvrStatus = false;
        Debug.Log("off");
        this.gvrTimer = 0;
        this.imgCircle.fillAmount = 0;
    }
}
반응형
: