Exemplo n.º 1
0
    Vector2 InitVelocity(Vector2 val, int i, int j)
    {
        if (m_obstacle[ij2index(i, j)] != OBSTACLE_EMPTY)
        {
            return(Vector2.zero);
        }
        // set up test ray and mask
        Vector3 pos = ij2Pos(i, j);

        pos.z += -5.0f;
        Ray ray = new Ray();

        ray.direction = Vector3.forward;
        ray.origin    = pos;
        float distance = 20f;
        int   mask     = LayerMask.GetMask("WindGenerator");

        RaycastHit[] hitInfo = Physics.RaycastAll(ray, distance, mask);           // if there is land in forward
        if (hitInfo != null)
        {
            foreach (RaycastHit hit in hitInfo)
            {
                WindGenerator generator = hit.collider.gameObject.GetComponent <WindGenerator>();
                if (generator != null)
                {
                    return(generator.GetVelocity(ij2Pos(i, j)));
                }
            }
        }


        RaycastHit2D[] hitInfo2d = Physics2D.GetRayIntersectionAll(ray, distance, mask);
        if (hitInfo2d != null)
        {
            foreach (RaycastHit2D hit in hitInfo2d)
            {
                WindGenerator generator = hit.collider.gameObject.GetComponent <WindGenerator>();
                if (generator != null)
                {
                    return(generator.GetVelocity(ij2Pos(i, j)));
                }
            }
        }

        return(Vector2.zero);
    }