- Home /
How can i using a break point if a gameobject have a collider after added to it ?
void Start()
{
waypoints = GameObject.FindGameObjectsWithTag("ClonedObject");
robots = GameObject.FindGameObjectsWithTag("Robots");
AddColliderToWaypoints();
originalPosition = robots[0].transform.position;
reverseOriginalPosition = robots[1].transform.position;
}
And the AddColliderToWaypoints
void AddColliderToWaypoints()
{
foreach (GameObject go in waypoints)
{
SphereCollider sc = go.AddComponent<SphereCollider>() as SphereCollider;
sc.isTrigger = true;
}
}
Then i put a break point in the Start function once on the line:
AddColliderToWaypoints();
And then i'm using the mouse to look on the waypoints array and look into the first gameobject. It should be without a collider yet but how do i know it when looking on the gameobject in the array ?
And then i put a break point on the next line after the AddColliderToWaypoints(); to see if it's added the colliders and again i'm looking on the first waypoints array gameobject item but i don't see something else or new that added to it.
what am i missing ? Or what/where should i looking for in the gameobject properties after added a collider to it ?
Answer by UnityCoach · Feb 28, 2017 at 12:52 PM
You can check it now has a collider, like gameObject.GetComponent<SphereCollider>() != null
. Unless you really want to use break points, you can also use Debug.Log()
and Debug.Break();
The latter will pause the runtime, the former will output anything you pass to it, and can highlight a game object that you pass as second parameter. Like
if (gameObject.GetComponent<SphereCollider>() == null)
Debug.Log ("object doesn't have sphere collider", gameObject);
Then if you click on the message on the console, it will highlight the game object. Note that you can pass components and not just game objects.