Unity下使用暴风魔镜SDK通过头部和手柄控制字体拼凑(二)
来源:互联网 发布:java http断点上传 编辑:程序博客网 时间:2024/06/04 19:48
工程如下图,按照笔划顺序给笔划命名
stroke下的物体是笔划实体,tag是Font,加碰撞体
originalStrokePositionParent下的是笔划实体原本待在的地方,tagboardStrokePosition
position是墙上希望笔划应该待在的地方,tag是wallStrokePosition,加碰撞体
代码如下:
选择笔划及控制移动
using UnityEngine;using System.Collections;namespace MojingSample.CrossPlatformInput.PlatformSpecific{ public class FontMove : MonoBehaviour { public static FontMove _instance; private GameObject lacuchPosition;//射线发射位置 public GameObject targetMoveObject = null;//被拾起的笔画 public LayerMask moveLayer;//移动层 public LayerMask wallLayer;//墙体层 public bool isMove = false;//是否可以移动 public bool isFind = true;//是否可以寻找 private Vector3 lastPosition; private int strokeNumber=1;//记录笔画顺序 void Awake() { _instance = this; } void Start() { lacuchPosition = GameObject.FindGameObjectWithTag("MainCamera"); } // Update is called once per frame void Update() { FindTarget(); if (isMove == true) TargetMove(); } void FindTarget() {//寻找需要选择的笔画 if (isFind == true) if (CrossPlatformInputManager.GetButtonDown("C") || Input.GetKeyDown(KeyCode.J)) { RaycastHit info; bool hit = Physics.Raycast(lacuchPosition.transform.position, lacuchPosition.transform.forward, out info, 100); if (hit) { if (info.transform.tag == "Font") { if (info.transform.name == strokeNumber.ToString()) {//如果满足要求的笔划顺序 targetMoveObject = info.transform.gameObject; lastPosition = targetMoveObject.transform.position; isMove = true; isFind = false; targetMoveObject.GetComponent<BoxCollider>().enabled = false; strokeNumber++; } } } } } void TargetMove() {//移动笔画 if (targetMoveObject != null) { RaycastHit info; bool hit = Physics.Raycast(lacuchPosition.transform.position, lacuchPosition.transform.forward, out info, 100); if (hit) { if (info.transform.tag == "Wall") { Vector3 pos = info.point; pos -= new Vector3(0.1f, 0, 0); targetMoveObject.transform.position = pos; } } } } }}控制笔划匹配
using UnityEngine;using System.Collections;namespace MojingSample.CrossPlatformInput.PlatformSpecific{ public class FontAlign : MonoBehaviour { private GameObject[] wallStrokePosition;//墙上应该被放置的笔画的位置 private GameObject lacuchPosition;//笔画向墙发射射线的位置 private GameObject targetStroke = null;//墙上被选中的笔画 // Use this for initialization void Start() { wallStrokePosition = GameObject.FindGameObjectsWithTag("wallStrokePosition"); } // Update is called once per frame void Update() { if (FontMove._instance.targetMoveObject != null) { lacuchPosition = FontMove._instance.targetMoveObject; } FindPosition(); } void FindPosition() { if (lacuchPosition != null) { foreach (GameObject go in wallStrokePosition) { if (go.name == lacuchPosition.name) { targetStroke = go; } } if (FontMove._instance.targetMoveObject != null) if (Vector3.Distance(lacuchPosition.transform.position, targetStroke.transform.position) <= 0.5f) { FontMove._instance.isMove = false; FontMove._instance.isFind = true; FontMove._instance.targetMoveObject.transform.position = targetStroke.transform.position; FontMove._instance.targetMoveObject = null; } } } }}
有不足的地方或者更好地解决办法希望大家能指出哦
0 0
- Unity下使用暴风魔镜SDK通过头部和手柄控制字体拼凑(二)
- Unity下使用暴风魔镜SDK通过头部和手柄控制字体拼凑(一)
- Unity下使用暴风魔镜SDK通过头部和手柄控制字体拼凑
- Unity中使用暴风魔镜蓝牙手柄
- Unity中使用暴风魔镜蓝牙手柄
- Unity使用暴风魔镜VR游戏开发
- 暴风魔镜与手柄相关的事件
- Unity中使用暴风魔镜进行VR游戏开发
- Unity中使用暴风魔镜进行VR游戏开发
- Unity Input 通过蓝牙手柄控制游戏
- 暴风魔镜安卓手柄输入检测接口
- 第一人称视角漫游(unity + 暴风魔镜)
- 暴风魔镜VR(第一人称和第三人称)
- 暴风魔镜VR(第一人称和第三人称)
- 暴风魔镜SDK在Unity3D 5.6中的简单应用
- 暴风魔镜VR_凝视
- 暴风魔镜中的凝视
- Unity使用游戏手柄输入
- 测试驱动开发
- (IOS开发)使用afn往服务器传图片
- makefile 的编写
- 整理了一些安卓的activity启动常量
- Ubuntu修改/root分区的大小
- Unity下使用暴风魔镜SDK通过头部和手柄控制字体拼凑(二)
- 小米手机与魅族手机判断悬浮框是否开启
- Android Studio运行Java的方法
- 15章示例8
- android 编译错误 unable to execute DX
- Android Studio:Failed to load the LayoutLib
- 数据业务建立流程之APN参数的激活
- Swift 数值型字面量
- (iOS开发)修改textfeiled中placeholder的字体,颜色,大小