OnTriggerStay to detect objects inside of another

I am trying to write a script that will detect if there are “screw” game objects inside of them. If there are screw objects then the statement is true. If there are no screw game objects inside of the object then statement is false.

I have the screw game objects with a tag of “screw”. I placed them inside of a capsule game object. I attached a script with the below code to the capsule and I it says MissingMethodException: Method not found: ‘UnityEngine.CapsuleCollider.FindWithTag’. I think I might not be using FindwithTag appropriately. Any idea how I might correct this?

var screws;

function OnTriggerStay (collision : Collider) 
{	
	screws = collision.FindWithTag("screw");
	
	if(screws != null)
		{
		screwCount == false;
		}
}

FindWithTag is a static GameObject function. You don’t call it on an instance of an object. I’m not familiar with Javascript, but in C# this wouldn’t compile. The correct use would be GameObject.FindWithTag(“screw”). But that won’t find screws within the object, that will just find one screw in that scene that has that tag.

Alternatively, you could use “if(collision.gameObject.tag == “screw”)” to see if the collider is a screw.

Like LiamAtDevour has already stated, “FindWithTag” is a funciton of the GameObject class (Unity - Scripting API: GameObject.FindWithTag) and as such will not work otherwise.

To find if there are “screw” objects inside your capsule you first need to set the capsules collider to trigger then use:

function OnTriggerStay(collision : Collider)
{
    if(collision.gameObject.CompareTag("screw"))
    {
        // do what is neccessary with this collision object as it's a screw
    }
    else
    {
    }
}