示例#1
0
    public static GameObject DrawTunnelLine(Vect3 startPos, Vect3 endPos, float scalingFactor, float width, float height, GameObject parent = null)
    {
        GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

        if (parent)
        {
            cylinder.transform.parent = parent.transform;
        }

        startPos.y += height / (2f * scalingFactor);
        endPos.y   += height / (2f * scalingFactor);

        Vect3 localVect = startPos - endPos;

        cylinder.transform.position   = GetVector3FromVect3(Vect3.MiddlePoint(startPos, endPos));
        cylinder.transform.localScale = new Vector3(width / scalingFactor, (float)localVect.Length() / 2, height / scalingFactor);
        Vector3 crossedVector = Vector3.Cross(GetVector3FromVect3(localVect), cylinder.transform.right);

        if (crossedVector == Vector3.zero)
        {
            crossedVector = Vector3.Cross(GetVector3FromVect3(localVect), cylinder.transform.forward);
        }
        cylinder.transform.rotation = Quaternion.LookRotation(crossedVector,
                                                              GetVector3FromVect3(localVect));
        return(cylinder);
    }