Michael
Michael

Reputation: 13

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?

enter image description here

Upvotes: 1

Views: 7768

Answers (1)

David
David

Reputation: 16277

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

enter image description here

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.

enter image description here

Upvotes: 4

Related Questions