Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Set percentage values of LODGroup?

Discussion in 'Scripting' started by Thiago-Crawford, Dec 17, 2014.

  1. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    Hi,

    I want to set the percentage values for the LODGroups via script, but I cannot access those properties.
    I searched and read some solutions, but don't think they refer exactly to what I want.

    If you see the attached image, those % values in the red box are what I want to change via script.

    Can it be done, if so, how? (It's fine if I can change them in the editor, doesn't have to be at run time)

    I have a lot of objects with this component, so going in and changing them manually would be EXTREMELY painful...not to mention this probably wont be the last time I do something of this sort!

    Thanks!

    LODScreenCap.jpg
     
    Last edited: Dec 18, 2014
  2. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    Nothing? :eek:



    EDIT:
    Solved it myself! with the help from this thread http://forum.unity3d.com/threads/access-to-lodgroup-data-in-script.123610/


    Here is part of my code:

    Code (CSharp):
    1. LODGroup lodGroup = gObj.GetComponent<LODGroup>();
    2. if (lodGroup != null) {
    3.     //Debug.Log(lodGroup.);
    4.  
    5.     SerializedObject obj = new SerializedObject(lodGroup);
    6.  
    7.     SerializedProperty valArrProp = obj.FindProperty("m_LODs.Array");
    8.     for (int i = 0; valArrProp.arraySize > i; i++) {
    9.         SerializedProperty sHeight = obj.FindProperty("m_LODs.Array.data[" + i.ToString() + "].screenRelativeHeight");
    10.  
    11.         if (i == 0) {
    12.             sHeight.doubleValue = 0.7;
    13.         }
    14.         if (i == 1) {
    15.             sHeight.doubleValue = 0.5;
    16.         }
    17.         if (i == 2) {
    18.             sHeight.doubleValue = 0.1;
    19.         }
    20.     }
    21.     obj.ApplyModifiedProperties();
    22. }
    23.  
     
    Last edited: Dec 18, 2014
    imDanOush likes this.
unityunity