Search Unity

Dynamic sliders acting strange

Discussion in 'Scripting' started by chubbspet, Sep 5, 2011.

  1. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    Hi guys, I will be so greatful if someone can help me with this...

    I have a type Slider where I store basic slider properties like Label, min, max and Def positions. I then store all of my Slider instances in a list of type Slider. All fine so far, but when I try to itterate through my list of SLider instances and then update some objects based on the result, it seems to skip every second object. Sorry, this is very hard to explain, but here is the meat of the code where I think the problem resides:

    Code (csharp):
    1.                 for (int i = 0; i < propSource.Count; i++)
    2.                 {
    3.                     if (slider.Label == propSource[i].Trim())
    4.                     {
    5.                         //Debug.Log(slider.Label + "/  " + propControl[i]);
    6.                         if (propTargetProp[i].Trim() == "x")
    7.                         {
    8.                             //Debug.Log("XVal: " + GameObject.Find(propTarget[i].Trim()).name);
    9.                             GameObject.Find(propTarget[i].Trim()).rigidbody.position = new Vector3(slider.Value, transform.position.y, transform.position.z);
    10.                         }
    11.                         if (propTargetProp[i].Trim() == "y")
    12.                         {
    13.                             //Debug.Log("YVal: " + GameObject.Find(propTarget[i].Trim()).name);
    14.                             GameObject.Find(propTarget[i].Trim()).rigidbody.position = new Vector3(transform.position.x, slider.Value, transform.position.z);
    15.                         }
    16.  
    17.                     }
    18.                    
    19.                 }
    When I create 2 test sliders - interresting thing is that all the Debug results shows exactly what i expect them to be, but only the y value of the object gets updated, wow, I'm stumped on this one.

    Any help? Thansk
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
  3. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    no matter, got it sorted by setting the individual transforms to the correct gameobject