unity, 鼠标与场景交点
在鼠标与场景交点上放一个mark,并于1s后消失:
新建一个空GameObject,命名为moushHitTest,添加下面脚本:
using UnityEngine;
using System.Collections;
public class mouseHit : MonoBehaviour {
public GameObject m_moushHitMarkPrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {//left button down
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo;
float camRayLength = 100f;
bool isHit = Physics.Raycast (camRay,out hitInfo,camRayLength);
if (isHit) {
Debug.Log(hitInfo.point);
Debug.Log(hitInfo.transform.gameObject.name);
Object instance=Instantiate (m_moushHitMarkPrefab, hitInfo.point, Quaternion.identity);
instance.name="hitMark";
//about startCoroutine and yield: http://stackoverflow.com/questions/12932306/how-does-startcoroutine-yield-return-pattern-really-work-in-unity
StartCoroutine(delayDestroy(instance));
}
}
}
IEnumerator delayDestroy(Object instance){
yield return new WaitForSeconds (1.0f);
Destroy (instance);
}
}
最新文章
- jQuery效率提升建议
- hoj 2634 How to earn more
- Debian普通用户获取root权限|sudo的安装与配置
- C++函数模版
- 使用jquery实现简单的拖动效果,分享源码
- html标签属性大全
- 七 mybatis的延迟加载
- html2canvas 踩坑总结
- distinct和group by 去掉重复数据分析
- 指定路径下建立Access数据库并插入数据
- 【js高程学习笔记】关于变量值和函数参数
- BZOJ4391 High Card Low Card [Usaco2015 dec](贪心+线段树/set库
- oracle常用分析函数 over(partition by xxx order by xxx)
- 原生java读取存储为xml格式的数据,并存储到java bean里
- asp.net导出excel 问题及服务器的部署dcom组件配置
- 【Spring学习笔记-MVC-10】Spring MVC之数据校验
- ubuntu 16.04 docker下安装klee环境
- zabbix第一篇:zabbix安装及使用
- 详解JavaScript的splice()方法
- 【BZOJ5100】[POI2018]Plan metra 构造
热门文章
- BusyBox 简化嵌入式 Linux 系统
- 使用cwrsync做服务器文件夹同步
- arcgis python图形信息
- ICLR 2013 International Conference on Learning Representations深度学习论文papers
- sql数据库出现可疑
- CSS:CSS层叠样式表的概述
- Python 谷歌翻译
- 关于在Visual Studio 2008/2010 和Opencv平台下出现LINK : fatal error
- SCU 4313 把一棵树切成每段K个点 (n%k)剩下的点不管
- DAS存储未死,再次欲获重生