Giant vs Human 팀프로젝트 개발일지

[Giant vs Human 팀프로젝트, Meta Quest, VR, Oculus] UI 작업 - 게임시작 시 Start버튼 따라다니기, 남은 거리 보여주기 및 남은 시간 보여주기

다모아 2023. 11. 29. 20:05

 

CenterEye에다가 Canvas 넣어주기

 

그래서 머리가 움직여도 계속 얼굴 앞을 따라다니게 만들어준다.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class TestCountDownDistance : MonoBehaviour
{
    [SerializeField] private Transform giantTr; //거인 위치
    [SerializeField] private Transform endTr; // 목적지
    [SerializeField] private TMP_Text countDownTxt; //남은시간
    [SerializeField] private TMP_Text distanceTxt; //남은거리
    [SerializeField] private GameObject startGo; //시간시작
    private float timer = 60f;
    private float distance = 0f;
    private float truncatedTimer;
    private float truncatedDistance;
    // Update is called once per frame
    void Update()
    {
        this.distance = this.endTr.position.x - this.giantTr.position.x;

        if (this.startGo.activeSelf == false)
        {
            this.timeAttack();
            this.goalDistance();
        }
    }

    private void timeAttack()
    {
        this.timer -= Time.deltaTime;
        this.truncatedTimer = Mathf.Floor(this.timer * 100f) / 100f;
        this.countDownTxt.text = this.truncatedTimer + "s";
    }

    private void goalDistance()
    {
        this.truncatedDistance = Mathf.Floor(this.distance * 100f) / 100f;
        this.distanceTxt.text = this.truncatedDistance + "m";
    }
}

 

아래 코드는 일단 임시로 보스가 목적지에 도착했을 때 몇미터 남았는지 알려주기 위해서 임시로 만들어줬다.

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

public class TestMove : MonoBehaviour
{
    [SerializeField] private GameObject giantGo;
    [SerializeField] private GameObject goalGo;
    [SerializeField] private float speed = 4f;
    void Update()
    {
        this.transform.position = Vector3.MoveTowards(this.transform.position, this.goalGo.transform.position, this.speed);
    }
}