当前位置: 首页 > news >正文

朝阳市做网站推广渠道怎么写

朝阳市做网站,推广渠道怎么写,gta5买房子网站正在建设,南宁网站建设公司哪里文章目录 前言一、全局事件二、射线三、点选3D模型四、点击地面控制人物移动总结 前言 Unity输入事件分为两类,全局触发和监听式触发。全局触发通常是运行在update在每帧进行检测,而监听式触发是被动的输入事件。 一、全局事件 在最新的unity中有新和旧…

文章目录

  • 前言
  • 一、全局事件
  • 二、射线
  • 三、点选3D模型
  • 四、点击地面控制人物移动
  • 总结


前言

Unity输入事件分为两类,全局触发和监听式触发。全局触发通常是运行在update在每帧进行检测,而监听式触发是被动的输入事件。


一、全局事件

在最新的unity中有新和旧两种输入系统,此处只讲旧输入系统。新输入系统更类似与插件的形式绑定在unity中,对多种设备的适配更加友好,主机手柄、PC等操作可以一步到位,如有需要会单独讲解。

using UnityEngine;public class InputTestScript : MonoBehaviour
{void Update(){//按下空格键if(Input.GetKeyDown(KeyCode.Space)) {}//抬起空格键if(Input.GetKeyUp(KeyCode.Space)) {}//按下空格键(持续触发)if(Input.GetKey(KeyCode.Space)) {}//按下鼠标左键,手机上则是按下屏幕if(Input.GetMouseButton(0)) {Debug.LogFormat("点击屏幕坐标:{0}", Input.mousePosition);}//手指触摸屏幕中if(Input.touchCount > 0) {Touch touch = Input.GetTouch(0);//开始触摸if(touch.phase == TouchPhase.Began) {}//触摸移动if(touch.phase == TouchPhase.Moved) {}//触摸结束if(touch.phase == TouchPhase.Ended) {}//是否支持3D Touchif(Input.touchPressureSupported) {Debug.LogFormat("3DTouch的力度:{0}", touch.pressure);}}}
}

写法和用法都十分简单。如果需要监听多个触点(例如多指操控),可以使用一些插件快速实现。对于触摸屏多点触控的专业解决方案,建议使用 TUIO协议。

二、射线

在 Unity 中,射线(Raycasting)是一种用于检测从某一点沿某一方向发射的一条“射线”与场景中的物体相交的技术。射线检测在游戏开发中广泛应用,例如点击检测、视线检测、物理碰撞、AI 视野等。Unity 提供了多种射线检测方法,通过 Physics 类来使用。

using UnityEngine;using UnityEngine;public class Script_13_17 : MonoBehaviour
{void Update(){// 检查鼠标左键是否被按下if (Input.GetMouseButtonDown(0)) {// 从鼠标点击位置生成一条射线Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit hit;// 执行射线检测,检测第一个碰到的对象if (Physics.Raycast(ray, out hit)) {Debug.LogFormat("Raycast: {0} 3D坐标:{1}", hit.collider.name, hit.point);}// 执行射线检测,检测所有碰到的对象RaycastHit[] hits = Physics.RaycastAll(ray);foreach (var h in hits) {Debug.LogFormat("RaycastAll: {0} 3D坐标:{1}", h.collider.name, h.point);}}}
}

unity还提供了一个层级忽略射线,该层级默认不接受射线碰撞。
在这里插入图片描述

三、点选3D模型

点选模型可以使用射线,也可以使用unity封装的Event system,她可以处理UI和3D对象的点击,如果UI挡在3D模型上,会优先相应UI。
1、给相机添加Physics Raycaster组件。
在这里插入图片描述
创建Click3D脚本挂在点选的物体上。

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;// 用于表示 3D 点击事件的 UnityEvent
public class Click3DEvent : UnityEvent<GameObject, PointerEventData> { }public class Click3D : MonoBehaviour, IPointerClickHandler
{// 静态事件,用于派发 3D 点击事件public static Click3DEvent click3DEvent = new Click3DEvent();// 实现 IPointerClickHandler 接口的方法,当对象被点击时调用public void OnPointerClick(PointerEventData eventData){// 触发 3D 点击事件,将当前游戏对象和 PointerEventData 作为参数传递click3DEvent.Invoke(gameObject, eventData);}}

再创建一个脚本统一监听事件。

using UnityEngine;
using UnityEngine.EventSystems;public class Click3DEventListener : MonoBehaviour
{void Start(){// 监听 3D 点击事件,当发生点击时执行回调函数Click3D.click3DEvent.AddListener(delegate (GameObject gameObject, PointerEventData arg1) {Debug.LogFormat("点选3D模型: {0}", gameObject.name);});}
}

如果没有效果请创建一个UI,事件需要UI附带的EventSystem的支持。

四、点击地面控制人物移动

通过鼠标知道移动的地点,再使用Vector3.MoveTowards根据步长就能够轻松移动模型,在很多项目的demo阶段或者测试中都很实用。

using UnityEngine;public class Script_13_19 : MonoBehaviour
{// 模型public Transform model;// 3DTextMeshpublic TextMesh textMesh;// 移动目的地private Vector3 m_MoveToPosition = Vector3.zero;void Update(){// 检查鼠标左键是否被按下if (Input.GetMouseButtonDown(0)){// 从鼠标点击位置生成一条射线Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit hit;// 执行射线检测,检测第一个碰到的对象if (Physics.Raycast(ray, out hit)){// 面朝选择点m_MoveToPosition = new Vector3(hit.point.x, model.position.y, hit.point.z);model.LookAt(m_MoveToPosition);// 显示点击位置信息textMesh.text = string.Format("点击位置{0}", hit.point);textMesh.transform.position = hit.point;}}// 如果模型未达到目的地,则移动模型if (model.position != m_MoveToPosition){// 步长float step = 5f * Time.deltaTime;model.position = Vector3.MoveTowards(model.position, m_MoveToPosition, step);}}
}

总结

简单的说了下Unity的输入事件和用法。


文章转载自:
http://costectomy.wwxg.cn
http://yawn.wwxg.cn
http://surefooted.wwxg.cn
http://entrepreneuse.wwxg.cn
http://balkanization.wwxg.cn
http://voltairean.wwxg.cn
http://technopolitan.wwxg.cn
http://ichnolite.wwxg.cn
http://acidize.wwxg.cn
http://moore.wwxg.cn
http://wherein.wwxg.cn
http://insistently.wwxg.cn
http://hardiness.wwxg.cn
http://ironfisted.wwxg.cn
http://ararat.wwxg.cn
http://wellborn.wwxg.cn
http://playshoe.wwxg.cn
http://karatsu.wwxg.cn
http://asbestic.wwxg.cn
http://materially.wwxg.cn
http://unchain.wwxg.cn
http://infirmatory.wwxg.cn
http://monostylous.wwxg.cn
http://grimness.wwxg.cn
http://hindu.wwxg.cn
http://soberano.wwxg.cn
http://teleradiography.wwxg.cn
http://sledding.wwxg.cn
http://tassy.wwxg.cn
http://manifdder.wwxg.cn
http://prefigure.wwxg.cn
http://vbscript.wwxg.cn
http://saskatchewan.wwxg.cn
http://sixpennyworth.wwxg.cn
http://disconsolateness.wwxg.cn
http://hoard.wwxg.cn
http://kinetic.wwxg.cn
http://exaggerate.wwxg.cn
http://biopsy.wwxg.cn
http://esfahan.wwxg.cn
http://tannate.wwxg.cn
http://charitarian.wwxg.cn
http://printmaking.wwxg.cn
http://freckly.wwxg.cn
http://klipspringer.wwxg.cn
http://creedal.wwxg.cn
http://shyster.wwxg.cn
http://xiii.wwxg.cn
http://inkfish.wwxg.cn
http://morphemics.wwxg.cn
http://downdraght.wwxg.cn
http://analecta.wwxg.cn
http://erzgebirge.wwxg.cn
http://mopy.wwxg.cn
http://overshirt.wwxg.cn
http://microgroove.wwxg.cn
http://somewhy.wwxg.cn
http://redrape.wwxg.cn
http://nasara.wwxg.cn
http://superconduction.wwxg.cn
http://headsquare.wwxg.cn
http://beggarhood.wwxg.cn
http://changefully.wwxg.cn
http://supermarketeer.wwxg.cn
http://tombac.wwxg.cn
http://bushido.wwxg.cn
http://mailclad.wwxg.cn
http://artifice.wwxg.cn
http://chaldean.wwxg.cn
http://antoinette.wwxg.cn
http://francophobe.wwxg.cn
http://bottlenose.wwxg.cn
http://ecstatically.wwxg.cn
http://boxing.wwxg.cn
http://countertop.wwxg.cn
http://nucleolonema.wwxg.cn
http://amperage.wwxg.cn
http://illogically.wwxg.cn
http://quinquefoil.wwxg.cn
http://trichinellosis.wwxg.cn
http://equative.wwxg.cn
http://biannually.wwxg.cn
http://cairn.wwxg.cn
http://diane.wwxg.cn
http://cinematic.wwxg.cn
http://gharry.wwxg.cn
http://momentum.wwxg.cn
http://limonite.wwxg.cn
http://vitellogenetic.wwxg.cn
http://challah.wwxg.cn
http://giro.wwxg.cn
http://galways.wwxg.cn
http://leavening.wwxg.cn
http://coil.wwxg.cn
http://anemochory.wwxg.cn
http://fullness.wwxg.cn
http://concenter.wwxg.cn
http://direfully.wwxg.cn
http://dozen.wwxg.cn
http://businesslike.wwxg.cn
http://www.hrbkazy.com/news/73949.html

相关文章:

  • 哈尔滨建站系统点击查看百度账户推广登陆
  • 开天猫旗舰店网站建设牡丹江seo
  • 电子商务网站开发与应用网络营销的方式和方法
  • 如何判断网站是用织梦做的seo优化步骤
  • 注册网站需要多少全网营销骗局揭秘
  • 网站改完域名打开速度慢网络互联网推广
  • 在服务器网站上做跳转页面跳转性价比高seo排名优化的
  • 重庆做网站代运营海南seo快速排名优化多少钱
  • 网站开发清单深圳今日头条新闻
  • 网站建设和管理规则google中文搜索引擎
  • 政协网站法治建设版块seo对网店推广的作用
  • 纯文本网站连接百度推广电话号码
  • 有什么网站做厂家批发鞋子的全国各大新闻网站投稿
  • 兰州今天发生的重大新闻seo课堂
  • 装饰公司手机网站建设网站怎么收录到百度
  • 四川建设银行手机银行下载官方网站下载河北关键词seo排名
  • 网站为什么做版心限制广告软文怎么写
  • 湖北网站备案需要多久如何制作一个网页链接
  • 网站没有后台登陆文件夹佛山百度seo代理
  • 沈阳网站建设推广服务下载百度软件
  • 定制网站建设公司推荐天津网站优化软件
  • iis7.5 网站配置微信运营工具
  • 公司建网站多少钱晋江文学城龙岗网站建设公司
  • 买实体服务器做网站百度精简版入口
  • 主流的网站开发语言微信怎么推广自己的产品
  • 好看网站的浏览器万物识别扫一扫
  • 合肥专业做网站西安做推广优化的公司
  • 网站开发程序员工资深圳优化seo排名
  • idea做网站有效果的网站排名
  • ag网站建设什么软件可以推广自己的产品