Question by
wilskin1 · Mar 17, 2020 at 11:34 PM ·
gameobjectcompareinstances
Why cant I get the object I want (UTS)
Hey so here is my problem. I am using UTS Pro which is working fine so far. UTS is spawning some cars(prefabs) for me and they will drive a given path. I added deactivated script to one of the prefabs and wrote some code where is will change to active when the car hits a collider.
if(playerTriggered == true && playerCounter<1 && gameobj.tag == "Car")
{
projections = GameObject.FindGameObjectsWithTag("Projection");
foreach(GameObject projection in projections)
{
if(projection.GetComponentInParent<Rigidbody>().GetInstanceID() == gameobj.GetComponentInParent<Rigidbody>().GetInstanceID())
{
walkPath = projection.GetComponentInParent<WalkPath>();
projection.GetComponentInParent<Idle>().enabled = true;
walkPath.setChangeCarPath(gameobj.gameObject);
}
}
playerCounter++;
}
This is working fine for me. When I press play and the car hits the collider I can see that the script is activated. In another class I tried running this code
if (car.gameObject.GetComponent<Idle>().enabled == true)
{
Debug.Log("UM - IF");
return points2[0, index];
}
else
{
return points[0, index];
}
The thing I dont understand is that the if statement is always false. Even though the car in the scene has an enabled script. I also tried comparing the instance-ids of ther passed gameobject with the car object. They also have different Ids.
Hope someone can help me and explain the problem.
Comment