Z
Z
Zimaell2020-10-27 13:18:30
Unity
Zimaell, 2020-10-27 13:18:30

How to disable/enable child element?

The Cell object has a SelectCell child element (selection frame), initially it should be turned off, the question is how to determine and turn it off immediately in the prefab and then turn it off / on from another script?
In the prefab creation script, they are created like this

Cells[Num] = Instantiate(Prefab new Vector3(x, y, 0), Quaternion.identity) as Cell;

the prefab appears immediately, of course, with the frame turned on ... I

found this option on the net
.........
public Transform SelectCell;
private void Start(){
  SelectCell = transform.Find("SelectCell");
  SelectCell.active = false;
  }
.........

it is located but you can’t turn it off because it is a Transform
'Transform' does not contain a definition for 'active' and no accessible extension method 'active'

that is, the Transform does not have the Active property, and that is, I do not need a Transform, but the entire child GameObject, but then I don’t get it by the GameObject type SelectCell = gameObject.Find("SelectCell");
Member 'GameObject.Find(string)' cannot be accessed with an instance reference; qualify it with a type name instead

Tell me how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Maximovich, 2020-10-27
@Zimaell

transform.gameObject.SetActive(false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question