A
A
Anton Vertov2018-05-29 19:00:42
C++ / C#
Anton Vertov, 2018-05-29 19:00:42

How to change the cellSize parameter of a GridLayoutGroup element from code?

Good day. I use the GridLayoutGroup element in the Unity3D engine.
I set the parameters in the cellSize Inspector to 100.
But in the code (C#), I want to make these values ​​change at the Start depending on the condition.
Can you please tell me how to change the cellSize parameter of the GridLayoutGroup element from the code? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2018-05-29
@1Frosty

1. Open the documentation for GridLayoutGroup.
2. See that literally the first property on the page is cellSize:
3. Write a script:

using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    public GridLayoutGroup gridLayoutGroup;

    private void Start()
    {
        gridLayoutGroup.cellSize = new Vector2(200, 200);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question