[GVR] 시선으로 이동, 래티클 사용해서 바라보면 멈추기

Unity3D 2021. 7. 30. 13:00
반응형

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

public class Player : MonoBehaviour
{
    private CharacterController controller;
    public static bool isStopped = false;

    // Start is called before the first frame update
    void Start()
    {
        this.controller = this.GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        if (isStopped) return;

        var dir = Camera.main.transform.TransformDirection(Vector3.forward);
        this.controller.SimpleMove(dir * 1.0f);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Cube4 : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IGvrPointerHoverHandler
{
    public void OnGvrPointerHover(PointerEventData eventData)
    {
        Debug.Log("Hover");
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("Enter");
        Player.isStopped = true;
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("Exit");
        Player.isStopped = false;
    }
}

 

 

 

 

 

Cube 다른 버전 

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

public class Cube : MonoBehaviour
{
    public float rotSpeed = 1.0f;

    bool isPressed = false;
    Material mat;

    private void Start()
    {
        this.mat = this.GetComponent<Renderer>().material;
    }

    public void Pressed() {
        this.isPressed = true;
        this.mat.color = Color.yellow;
    }

    public void Released() {
        this.isPressed = false;
        this.mat.color = Color.white;
    }

    private void Update()
    {
        if (this.isPressed) {
            this.transform.Rotate(Vector3.up * this.rotSpeed * Time.deltaTime);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Cube2 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        EventTrigger trigger = GetComponent<EventTrigger>();

        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerDown;
        entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
        trigger.triggers.Add(entry);

        EventTrigger.Entry entry2 = new EventTrigger.Entry();
        entry2.eventID = EventTriggerType.PointerUp;
        entry2.callback.AddListener((data) => { OnPointerUpDelegate((PointerEventData)data); });
        trigger.triggers.Add(entry2);
    }

    public void OnPointerDownDelegate(PointerEventData data)
    {
        Debug.Log("OnPointerDownDelegate called.");
    }

    public void OnPointerUpDelegate(PointerEventData data)
    {
        Debug.Log("OnPointerUpDelegate called.");
    }

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

public class Cube3 : MonoBehaviour
{

    public void OnLookAtCube(bool isLookAt) {
        Debug.Log(isLookAt);
    }
}
반응형
: