Search Unity

Trying to find a tag amount rigidbody objects

Discussion in 'Scripting' started by yoash, Apr 21, 2016.

  1. yoash

    yoash

    Joined:
    Sep 3, 2013
    Posts:
    36
    I have this code to find rigidbodies and see if they have stopped moving:

    Code (CSharp):
    1. Rigidbody2D[] bodies = FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[];
    2.         foreach (Rigidbody2D rb in bodies)
    3.             if (rb.velocity.sqrMagnitude > 1)
    4.                 return true;
    5.         return false;

    How can I make it only apply to certain gameoject's rigidbody. Basically I want this to only apply to objects with a certain tag instead of ALL rigidbodies.

    Thanks!
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    811
    You should still be able to get the tag from the rigidbody2D, so you could include the check in your current if statement.