Ray实际上就是一个Vector3,我们在调试的时候可以使用Debug.DrawRay()这个函数。注意这个函数可以设置ray的颜色,这样方便我们直观的看出来,这个debug的只能在scene的时候显示,因此需要我们开两个小的窗口,一个显示scene,一个显示game,而我们在game窗口进行操作的时候,scene那里就可以显示ray的位置了。简单的示例如下:
Color color = hit ? Color.green : Color.red;
Debug.DrawRay (transform.position, Vector3.forward * 10, color);
今天遇到的一个奇怪的bug,就是我创建了一个tk2dSprite,但即使我加入了box collider之后,还是无法产生raycast的hit事件,之后查阅很多网站,终于发现原来如果一个sprite是在sprite collection之中的话,那么这个sprite collection会定义这个sprite的collider的类型,如果是none,那么即使我们在外面定义box collider也是没有用处的,解决方案一种是在sprite collection中将类型变成user defined,另外就是在collection中定义好,然后外面不需要添加自己的collider即可。
官方作者的解释:
引用
The reason this is happening, is that you are trying to create your own collider, while the setting in the SpriteCollection for the particular sprite is "None".
When an object already has a box collider and the sprite is set to "None" collision, 2d toolkit will set its bounds to 0,0,0 and origin z to -100000. This is primarily for animation, for instance, if 5 frames of animation have a collider and 3 dont.
2 ways to solve this -
1. if you need to mange the collider yourself, set it to "Unset" in the sprite collection. This means, the sprite will not try to manage the collider, and you can do what you wish with it.
2. Set it to BoxTrimmed in the Sprite collection. You won't need to manage the collider any more at this point, and it will automatically fit the visible part of the texture.
Hope this helps.
分享到:
相关推荐
unity3d tk2d 2DToolkit 1.92 最终正式版
unity 2DSprite 边缘发光特效,制作unity 2D游戏很实用!
unity 2DSprite 边缘发光特效,制作unity 2D游戏很实用!很牛逼的发光效果,sprite 发光效果,点灯元
Unity3D开发的打鱼工程,网络部分已屏蔽,单机版可玩。
Unity 2D特效资源包 2DxFX 2D Sprite FX v2.3.7.unitypackage
UNITY 开发文本插件
文章《Unity3D学习笔记07:射线Ray实现点击拾取》的项目源码
Unity2d 模拟东西掉入水中,水面波澜效果,波动幅度,范围有参数控制组件添加:BuoyancyEffector2D 支持物体掉入水中的浮力,2d游戏水插件
UnityRayMarching Unity Raymarching示例示例1:我尝试根据有关Raymarching的AlanZucconi文章实施此着色器 示例2:游览 示例3:体素环面 示例3:重复 示例4:分数布朗运动去做: 1,帮助我进行示例2中的纹理贴图之旅...
AE2Unity After Effect To Unity Animation AE动画导入到Unity
Unity 重新设置Texture2D的大小
Unity游戏代码 ,Unity经典游戏源码 , Unity休闲游戏源码, Unity容易上手的游戏源码,Unity小游戏源码,Unity新手练习源码,Unity个人开发源码,Unity优秀项目,Unity商店优秀作品。 unity多人RPG游戏源码uMMORPG 2D 1.3,...
在unity3d里面把Bitmap格式转为Texture2D的格式,使用C#语言
toolkit 2d,unity 2D游戏制作不可缺少的插件
AE2Unity动画插件
Unity用来和服务器通信可以用原生的WWW,但是WWW所提供的功能并不多,不能满足很多需求。因此我们可以自己封装Http协议来满足更多的需要。在Unity游戏里使用Http协议的情况很常见,因为它操作简单,便于实现,经常用...
Unity游戏代码 ,Unity经典游戏源码 , Unity休闲游戏源码, Unity容易上手的游戏源码,Unity小游戏源码,Unity新手练习源码,Unity个人开发源码,Unity优秀项目,Unity商店优秀作品。 Unity精品农场经营游戏源码unity完整...
农场业务第2版农场unity3d教程 unity塔防游戏源码 Unity精品小游戏源码 , Unity完整项目源码 是完整的项目压缩包 , 新建空项目直接导入到项目里面就可以运行了,无需其他操作。 适合二次开发和学习使用,都是经典游戏...
最新Unity插件SteamVR Plugin steamvr_2_8_0.unitypackage最新Unity插件SteamVR Plugin steamvr_2_8_0.unitypackage最新Unity插件SteamVR Plugin steamvr_2_8_0.unitypackage最新Unity插件SteamVR Plugin steamvr_2_...
unity2D跳跃游戏demo 源码、适用unity2018以上