void Update (){
if(Input.GetMouseButton()){
//从摄像机发出到点击坐标的射线
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if(Physics.Raycast(ray,out hitInfo)){
//划出射线,只有在scene视图中才能看到
Debug.DrawLine(ray.origin,hitInfo.point);
GameObject gameObj = hitInfo.collider.gameObject;
Debug.Log("click object name is " + gameObj.name);
//当射线碰撞目标为boot类型的物品,执行拾取操作
if(gameObj.tag == "boot"){
Debug.Log("pickup!");
}
}
}
}

【Unity笔记】经典的鼠标点击射线检测碰撞的更多相关文章

  1. 【Unity笔记】获得鼠标点击屏幕的位置,并转成世界坐标

    Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

  2. unity3D基础学习 通过判断鼠标点击的是否是目标物体,物体旋转,滑动滚轮缩放拉近视角

    贴代码: 摄像机的拉近视角代码: public Transform target;     public float minFov = 15f;     public float maxFov = 7 ...

  3. Unity——射线检测(鼠标点击开关门效果)

    Unity射线检测--实现简单的开关门效果 简要:通过鼠标点击来发射一条射线,来获得射线所碰到的物体名称,再通过改变门的Rotation值来实现开关门的效果. 一.代码实现 1.1 简易的场景搭建 注 ...

  4. unity提高----------射线使用【unity3d 怎样获得当前鼠标点击的对象】

    unity3d 怎样获得当前鼠标点击的对象 最佳答案   var ray = Camera.main.ScreenPointToRay (Input.mousePosition);var hit : ...

  5. unity中让物体移动到鼠标点击地面任一点的位置(单击移动和双击暂停移动)并生成图标

    using UnityEngine; using System.Collections.Generic; using UnityEngine.EventSystems; using UnityEngi ...

  6. unity中让摄像机移动到鼠标点击的位置和鼠标控制平移视角

    private Vector3 targetVector3; private float movespeed=0.5f; private bool IsOver = true; private Gam ...

  7. Layabox 3D游戏开发学习笔记---射线检测,鼠标控制物体运动

    核心要点:3D物体碰撞是靠射线检测,射线与碰撞器相撞获取对应的碰撞点信息. class RayPicking03 { private ray: Laya.Ray; private point: Lay ...

  8. Unity —— 通过鼠标点击控制物体移动

    //ClickMove - - 通过鼠标点击控制物体移动 using System.Collections; using System.Collections.Generic; using Unity ...

  9. Unity的学习笔记(射线检测)

    首先,射线检测的API是这样的,网上找了一下,这个图片看得很清楚: 接下来是自己使用这个进行测试 using System.Collections; using System.Collections. ...

随机推荐

  1. ie上画圆饼图

    概述 主要运用到CSS3的transform.js.jq实现饼状图效果 详细 代码下载:http://www.demodashi.com/demo/10579.html 一.准备工作 1.主要运用到C ...

  2. jQuery正则:电话、身份证、邮箱简单校验

    if (!(/^1[3,5,6,7,8,9]\d{9}$/).test(e.detail.value.data_phone)) { wx.showToast({ title: '请输入有效11位手机号 ...

  3. <%@ include file="">和<jsp:include file="">区别

    <%@include file="a.jsp"%>是在编译时加入,所谓静态,就是在编译的时候将jsp的代码加入进来再编译,之后运行. <jsp:include p ...

  4. github常见操作和常见错误及其解决办法

    一.常见操作 1. 使用git在本地创建一个项目的过程 $ makdir ~/hello-world //创建一个项目hello-world $ cd ~/hello-world //打开这个项目 $ ...

  5. WordPress 博客文章中google adsense广告展示方法之一

    http://log.medcl.net/item/2011/08/diving-into-elasticsearch-4-installation-and-configuration/ 看到这个网站 ...

  6. Linux进程冻结技术

    1 什么是进程冻结 进程冻结技术(freezing of tasks)是指在系统hibernate或者suspend的时候,将用户进程和部分内核线程置于“可控”的暂停状态. 2 为什么需要冻结技术 假 ...

  7. nginx实战五

    nginx用户认证 https://coding.net/u/aminglinux/p/nginx/git/blob/master/access/auth.md 当访问一些私密资源时,最好配置用户认证 ...

  8. Python hypot() 函数

    描述 hypot() 返回欧几里德范数 sqrt(x*x + y*y). 语法 以下是 hypot() 方法的语法: import math math.hypot(x, y) 注意:hypot()是不 ...

  9. STM32 usb_mem.c和usb_sil.c文件的分析

    转:http://blog.csdn.net/u011318735/article/details/17424515 这两个c文件都还算是很简单的,先讲讲usb_mem.c这个文件.从文件名就能知道跟 ...

  10. hive sql 修改列名

    ALTER TABLE dev.dev_jypt_jiadian_cate3_pred_20181109 CHANGE utem_third_cate_name item_third_cate_nam ...