COOKIES

This site may be using cookies to melk you with your own data. I, ben0bi, am not the owner of this web service and I also do not maintain their servers. But the EU and the owner of this service think, that the user (me) has the responsibility to inform the consumer (you), that this website uses cookies. Again: I, ben0bi, NEVER use cookies. I am not responsible for the setup of this web service. I just present some information here and do not intend to spy on you for whatever reason ever. But (also again), I do not host this website nor do I maintain any servers related to this website nor do I benefit from using the cookies maintained from this service. I hereby give the responsibility for using cookies on blogspot back to the owners of blogspot.

Montag, 18. November 2019

Unity: NavMesh-Debugging

Um ein Waypoint-System zu bauen habe ich mich informiert, wie man eine Linie in Unity zeichnen kann. Das kann man auch NUR IM EDITOR, was sehr hilfreich ist.

Dazu gibt es die Funktionen "OnDrawGizmos" und "OnDrawGizmosSelected".

Hier ist der Code, welcher eine Linie vom aktuellen zum nächsten NavMesh-zieht.

Erstelle dieses Script, hänge es an ein GameObject ran und ziehe dir ein Prefab davon:

public class NavCon
{
   public GameObject nextWaypoint;
   protected Color actualColor = Color.blue;

   private void OnDrawGizmos()
   {
        if(nextWaypoint)
        {
            Gizmos.color = actualColor;
            Gizmos.DrawLine(gameObject.transform.position, nextWaypoint.transform.position, actualColor);
        }
        // reset the color.
        actualColor = Color.blue
   }

   private void OnDrawGizmosSelected() {actualColor = Color.green;}
}


Wenn du nun ein anderes GameObject auf das "nextWaypoint"-Feld im Inspector ziehst, wird im Editor eine blaue oder grüne Linie zwischen den beiden GameObjects gezeichnet. Da es keine "OnDrawGizmosUnselected"-Funktion gibt, muss die Farbe nach jedem Zeichnen ge-resetted werden.