[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;
}
}
반응형
'Unity3D' 카테고리의 다른 글
Vuforia AR (0) | 2021.07.30 |
---|---|
[GVR] 360VR (0) | 2021.07.30 |
Unity CharacterController Move / SimpleMove 차이 (0) | 2021.07.30 |
[GVR] 시선으로 이동, 래티클 사용해서 바라보면 멈추기 (0) | 2021.07.30 |
유랑님 블로그 (유니티 튜토리얼) (0) | 2021.07.30 |