Search Unity

Need help with FindObjectsOfType

Discussion in 'Scripting' started by dijital, Aug 4, 2016.

  1. dijital

    dijital

    Joined:
    Apr 28, 2010
    Posts:
    232
    Hi,

    I need a little help with FindObjectsOfType.

    Im trying to find every rigidbody in my scene and change its drag, ive tried using the c# example from

    http://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html

    but I keep getting varying errors.

    I don't usually ask people to write scripts for me but as this is such a short one I would appreciate it if anybody could help me out here.

    Thanks.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    If you show your code and maybe an error, we could tell you what is wrong. The example they give in the doc is pretty accurate, that is why I'm suggesting this instead. Also, this may help us determine if there may be a better way to do this.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    I prefer to use the generic method not described in that doc

    Code (CSharp):
    1. Rigidbody[] rigidbodies = FindObjectsOfType<Rigidbody>();
    2.  
    3. foreach(Rigidbody body in rigidbody){
    4.     body.drag = 0f;
    5. }