/// <summary> /// Adds a new waypoint to our path and orders the path accordingly. /// </summary> /// <param name='waypoint'> /// Waypoint. /// </param> public void AddWaypoint(PatrolPathWaypoint waypoint) { //Make sure duplicate sequence ordering is not entered if (waypoints.ContainsKey(waypoint.orderInSequence)) { Debug.LogError("Duplicate order no. in PatrolPathWaypoint on object: " + waypoint.gameObject.name); return; } waypoints.Add(waypoint.orderInSequence, waypoint); ValidateWaypoints(); }
public override void OnInspectorGUI() { PatrolPath path = (PatrolPath)target; //Add a button that will add new waypoints if (GUILayout.Button("Add Waypoint")) { //Call Start() on the path so its waypoint data is initialised path.Start(); //Create the new object to house our waypoint GameObject newWaypoint = new GameObject(); newWaypoint.name = "Waypoint" + path.Size(); newWaypoint.transform.parent = path.transform; newWaypoint.transform.localPosition = Vector3.zero; //Create the waypoint component instance PatrolPathWaypoint waypoint = newWaypoint.AddComponent <PatrolPathWaypoint>(); waypoint.orderInSequence = path.Size(); //Add it to the path! path.AddWaypoint(waypoint); } }