简体   繁体   中英

Unity3D: How to modify Grid Layout Group component by script

is there any way to change component setting of Constraint: "Fixed Row Count", by script, and then assigning constraint count to 1?

在此处输入图片说明

Create a script, .eg test.cs, add/attach this script to the same game object as the GridLayoutGroup:

在此处输入图片说明

public class test : MonoBehaviour {

    GridLayoutGroup glg;

    void Start () {        
        glg = gameObject.GetComponent<GridLayoutGroup>();
        Debug.Log(glg);
        glg.constraint = GridLayoutGroup.Constraint.FixedRowCount;  //**
        glg.constraintCount = 1;                                    //**
    }
}

Run the game, you will see this is automatically set to 1.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM