查看: 3909|回复: 0
打印 上一主题 下一主题

Unity 3d 射线(获得鼠标点击的坐标[x,y,z])

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-2-2 15:30:21 |只看该作者 |倒序浏览
using UnityEngine;

using System.Collections;
public class Lu : MonoBehaviour

{

public Camera cam;

// We need to actually hit an object

RaycastHit hitt = new RaycastHit();
// Use this for initialization

void Start()

{
}
// Update is called once per frame

void Update()

{

Ray ray = cam.ScreenPointToRay(Input.mousePosition);

Physics.Raycast(ray, out hitt, 100);

// Debug.DrawLine(cam.transform.position, ray.direction,Color.red);

if (null != hitt.transform)

{

print(hitt.point);//鼠标点击的坐标

}

}

}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-5 20:58 , Processed in 0.085951 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部