HoloLens开发——模型放大缩小复原

在unity里放三个button,分别放大、缩小、复原的点击响应


Unity中加上代码后,需要将放大缩小复原的GameObject 连接给GameObject 。

放大代码:

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class Big_Button : MonoBehaviour, IInputClickHandler
{
    public GameObject objBig;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }


    public void OnInputClicked(InputClickedEventData eventData)
    {
      

        Vector3 localScale = objBig. transform.localScale;

        Vector3 scale = new Vector3(1.1f* localScale.x, 1.1f*localScale.y, 1.1f* localScale.z);

        objBig.transform.localScale = scale;


    }
}



缩小代码:

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class Small_Button : MonoBehaviour, IInputClickHandler
{
    public GameObject objSmall;
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }


    public void OnInputClicked(InputClickedEventData eventData)
    {




        Vector3 localScale = objSmall.transform.localScale;

        Vector3 scale = new Vector3(0.9f * localScale.x, 0.9f * localScale.y, 0.9f * localScale.z);

        objSmall.transform.localScale = scale;




    }
}

复原代码:

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class ResetButton : MonoBehaviour, IInputClickHandler
{
    public GameObject objOrigi;

    void Start()
    {


    }
	
	


    /// <summary>
    /// 点击事件(包含手势点击和Clicker设备的点击)
    /// </summary>
    public void OnInputClicked(InputClickedEventData eventData)
    {
  
        Vector3 scale = new Vector3(1, 1, 1);

        objOrigi.transform.localScale = scale;

    }


}

也可以使用语音,作为输入,来进行缩放复原控制。


展开阅读全文
博主设置当前文章不允许评论。

没有更多推荐了,返回首页