Vuforia开发基础(四):模型选定与控制
2017-06-10 13:41
162 查看
public class RayPick : MonoBehaviour { public Material[] mats; public Texture[] texs; int i = 0; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//从摄像机发出到点击坐标的射线 RaycastHit hitInfo; if(Input.touchCount==1&&Input.GetTouch(0).phase==TouchPhase.Began){ if(Physics.Raycast(ray,out hitInfo)) { Debug.DrawLine(ray.origin,hitInfo.point);//划出射线,只有在scene视图中才能看到 GameObject gameObj = hitInfo.collider.gameObject; //gameObj.transform.parent.renderer.material = mats<i>;//设置父组件的材质 if(Input.GetTouch(0).tapCount==2){ gameObj.renderer.material.mainTexture = texs[i]; } //gameObj.renderer.material = mats<i>; //gameObj.transform.parent.gameObject.SetActive(true); // other gameobjects set false //checkIfPicked(gameObj.transform.parent.gameObject); Debug.Log("---->"+gameObj.transform.parent.gameObject.name); i++; if(i>=mats.Length-1){ i=0; } Debug.Log("click object name is " + gameObj.name); if(gameObj.tag == "boot")//当射线碰撞目标为boot类型的物品 ,执行拾取操作 { Debug.Log("pick up!"); } } } } } }
单击、双击、长按等:if(Physics.Raycast(ray,out hitInfo))
这个接下来触发的事件就是单击和长按。
复制代码
if(Input.touchCount == 1){ Touch touch = Input.GetTouch(0); if(touch.phase == TouchPhase.Began){ newTouch = true; touchTime = Time.time; }else if(touch.phase == TouchPhase.Stationary){ if(newTouch==true&&Time.time-touchTime>1){ Debug.Log("longpress!!!"); newTouch = false; longPressDetected = true; //touched_model_name = "long press!!!!!!!"; }else if(newTouch==false&&longPressDetected== false){ newTouch = true; touchTime = Time.time; Debug.Log("TouchTime = "+touchTime); } }else{ newTouch = false; longPressDetected = false; Debug.Log("setting newTouch false"); } }
双击:if(Input.GetTouch(0).tapCount==2)
判断单击的次数,如果为2,就是代表双击。
复制代码
if(Physics.Raycast(ray,out hitInfo)) { Debug.DrawLine(ray.origin,hitInfo.point);//划出射线,只有在scene视图中才能看到 GameObject gameObj = hitInfo.collider.gameObject; //gameObj.transform.parent.renderer.material = mats<i>;//设置父组件的材质 if(Input.GetTouch(0).tapCount==2){ gameObj.renderer.material.mainTexture = texs[i]; }}</i></i>
请尊重所有作者的劳动,转载请注明原帖来自 AR学院 !
相关文章推荐
- (Unity3d)Vuforia开发基础四-模型选定与控制
- Vuforia开发基础(三):模型替换
- (Unity3d)Vuforia开发基础三-模型替换
- (Unity3d)Vuforia开发基础五-模型交互
- Vuforia开发基础(五):模型交互
- SVN二次开发——让SVN、TSVN(TortoiseSVN)支持windows的访问控制模型、NTFS ADS (可选数据流、NTFS的安全属性)
- 软件开发基础模型
- unity基础开发----导入模型碰撞检测
- unity基础开发-- 动态改变模型大小、方向
- Lightswitch 业务基础平台开发与建筑行业解决方案模型,正式启动 !
- 黑马程序员——零基础学习iOS开发——04 c语言:基本运算、流程控制、函数
- SVN二次开发——让SVN、TSVN(TortoiseSVN)支持windows的访问控制模型、NTFS ADS(可选数据流、NTFS的安全属性)
- magento 开发 -- 深入理解Magento第四章 – 模型和ORM基础
- Android Studio开发基础之使用XML和Java代码混合控制UI界面
- 黑马程序员_iOS开发C语言基础之运算符和流程控制
- Magento开发文档(五):Magento模型与ORM基础
- Vuforia AR SDK对模型进行控制(平移、旋转、缩放)
- ABAP开发基础知识:10)数据流控制
- 基础:RUP模型中的迭代开发方式
- 【零基础学习iOS开发】【02-C语言】09-流程控制