没什么可说的,直接上代码。不明白的可以 加群【VR/AR独立开发者】:579825973

using HoloToolkit.Unity.InputModule;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System;

public class ObjectRotation : MonoBehaviour,

                                 IInputHandler,

                                 INavigationHandler

{

    private GameObject FocusedGameObject;

    private bool IsNavigating = false;

    public Vector3 NavigationPosition { get; private set; }

    public float RotationSensitivity = 10.0f;

    private float rotationFactorX;

    private float rotationFactorY;

    private float rotationFactorZ;

    void Update()

    {

        PerformRotation();

    }

    private void PerformRotation()

    {

        if (FocusedGameObject != null && IsNavigating)

        {

            rotationFactorX = NavigationPosition.x * RotationSensitivity;

            transform.Rotate(new Vector3(0, -1 * rotationFactorX, 0));

        }

    }

    public void OnInputDown(InputEventData eventData)

    {

        FocusedGameObject = gameObject;

    }

    public void OnInputUp(InputEventData eventData)

    {

        FocusedGameObject = null;

    }

    public void OnNavigationStarted(NavigationEventData eventData)

    {

        IsNavigating = true;

        NavigationPosition = eventData.CumulativeDelta;

    }

    public void OnNavigationUpdated(NavigationEventData eventData)

    {

        IsNavigating = true;

        NavigationPosition = eventData.CumulativeDelta;

    }

    public void OnNavigationCompleted(NavigationEventData eventData)

    {

        IsNavigating = false;

    }

    public void OnNavigationCanceled(NavigationEventData eventData)

    {

        IsNavigating = false;

    }

}


Logo

这里是“一人公司”的成长家园。我们提供从产品曝光、技术变现到法律财税的全栈内容,并连接云服务、办公空间等稀缺资源,助你专注创造,无忧运营。

更多推荐