码迷,mamicode.com
首页 > 其他好文 > 详细

Hololens缩放物体源码(待完善)

时间:2016-11-20 13:16:03      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:direct   unity   size   object   empty   forward   ant   set   blog   

using UnityEngine;
using System.Collections;
 
public class ScaleQuad : MonoBehaviour
{
 
public GameObject master; //Empty before the Quad
public GameObject quad; //The Quad I want to scale
Raycast hitInfo;
private Vector3 offsetOld;
 
 
void Update()
{
    var headPosition = Camera.main.transform.position;
    var gazeDirection = Camera.main.transform.forward;
 
    if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
    {
        //Create the offset
        offset = hitInfo.point - master.transform.position;
       
        // To get the new offset between hitpoint and master.transform.position for the new size
        Vector3 diff = offset - offsetOld;
 
        vFBMaster.transform.position = new Vector3((diff.x + master.transform.position.x), (diff.y + master.transform.position.y), master.transform.position.z);
        quad.transform.localScale = new Vector3((diff.x / 2) + quad.transform.localScale.x, (diff.y / 2) + quad.transform.localScale.y, quad.transform.localScale.z);
 
        Debug.Log(diff);
 
        //To save the old offset
        offsetOld = offset;
 
        Debug.Log("Old Offset = " + offsetOld);
        Debug.Log("new Offset = " + offset);
    }
}
}

 

Hololens缩放物体源码(待完善)

标签:direct   unity   size   object   empty   forward   ant   set   blog   

原文地址:http://www.cnblogs.com/unity3ds/p/6082217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!