Raycasting in Unity 2D c#

Ich bin neu in c# und versuchen herauszufinden, wie man raycasting arbeiten hier in Unity3d ist die neue 2d-Unterstützung.

Ich bin immer der Fehler "cannot convert from 'UnityEngine.Ray2D' to '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;

        }
    }

Kann mir jemand helfen?

  • Welche Zeile wird der Fehler auf?
  • wenn (Physics2D.Raycast(ray,out hit,Mathf.Abs(deltaY),collisionMask))
InformationsquelleAutor Kem | 2014-05-26
Schreibe einen Kommentar