Whenever I add the waypoints around my robot, my unity just closes itself. I don’t know if this is a GUI Problem but can somebody just help me anyway?
Can you post the code that handles the waypoints?
Which code is that? The autowaypoint one?
Well, you didn’t make it clear whether the crash occurs when you place the waypoints or when you try to use them afterwards. If you’re using an editor script to place them and Unity crashes when you do, it could well be that script that is causing the problem. If you get the crashes when you run the game, the fault might be with the script that uses the waypoints.
The crash starts like 5 seconds after I push the play button to test my game. I am using javascript.
OK, so can you post the code that uses the waypoints in the game?
It’s a long code. Are you sure you want to check it out. And I have windows. Anyways, here it is:
static var waypoints = Array();
var connected = Array();
static var kLineOfSightCapsuleRadius = 0.25;
static function FindClosest (pos : Vector3) : AutoWayPoint {
// The closer two vectors, the larger the dot product will be.
var closest : AutoWayPoint;
var closestDistance = 100000.0;
for (var cur : AutoWayPoint in waypoints) {
var distance = Vector3.Distance(cur.transform.position, pos);
if (distance < closestDistance)
{
closestDistance = distance;
closest = cur;
}
}
return closest;
}
@ContextMenu ("Update Waypoints")
function UpdateWaypoints () {
RebuildWaypointList();
}
function Awake () {
RebuildWaypointList();
}
// Draw the waypoint pickable gizmo
function OnDrawGizmos () {
Gizmos.DrawIcon (transform.position, "Waypoint.tif");
}
// Draw the waypoint lines only when you select one of the waypoints
function OnDrawGizmosSelected () {
if (waypoints.length == 0)
RebuildWaypointList();
for (var p : AutoWayPoint in connected) {
if (Physics.Linecast(transform.position, p.transform.position)) {
Gizmos.color = Color.red;
Gizmos.DrawLine (transform.position, p.transform.position);
} else {
Gizmos.color = Color.green;
Gizmos.DrawLine (transform.position, p.transform.position);
}
}
}
function RebuildWaypointList () {
var objects : Object[] = FindObjectsOfType(AutoWayPoint);
waypoints = Array(objects);
for (var point : AutoWayPoint in waypoints) {
point.RecalculateConnectedWaypoints();
}
}
function RecalculateConnectedWaypoints ()
{
connected = Array();
for (var other : AutoWayPoint in waypoints) {
// Don't connect to ourselves
if (other == this)
continue;
// Do we have a clear line of sight?
if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {
connected.Add(other);
}
}
}
It may not be the waypoints problem, but whenever I add the AI, AI Animation and Character Damage script to my robot this also happens.
I can’t see anything immediately wrong with that script, so perhaps one of the others is causing the problem. Is it possible for you to disable the scripts individually, or do they all depend on each other. If you disable them one at at time, you can probably narrow down the exact script that is giving you trouble.