【发布时间】:2014-05-26 01:43:47
【问题描述】:
我是 c# 的新手,正在尝试弄清楚如何在 Unity3d 的新 2d 支持中让光线投射在这里工作。
我收到错误“无法从 'UnityEngine.Ray2D' 转换为 'UnityEngine.Vector2'”
for (int i = 0; i<3; i ++) {
float dir = Mathf.Sign(deltaY);
float x = (p.x + c.x - s.x/2) + s.x/2 * i;
float y = p.y + c.y + s.y/2 * dir;
ray = new Ray2D(new Vector3(x, y), new Vector3(0, dir));
Debug.DrawRay(ray.origin, ray.direction);
hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Abs(deltaY), collisionMask);
if (hit != null && hit.collider != null)
{
}
if (Physics2D.Raycast(ray,out hit,Mathf.Abs(deltaY),collisionMask)) {
float dst = Vector2.Distance (ray.origin, hit.point);
if (dst > skin) {
deltaY = dst * dir + skin;
}
else {
deltaY = 0;
}
grounded = true;
break;
}
}
谁能帮帮我?
【问题讨论】:
-
错误出现在哪一行?
-
if (Physics2D.Raycast(ray,out hit,Mathf.Abs(deltaY),collisionMask))
标签: c# unity3d 2d raycasting