S
S
SHELLL902020-09-20 21:45:41
C++ / C#
SHELLL90, 2020-09-20 21:45:41

Accidentally activating a GameObject in Unity?

Good day!
I can not understand where the script activation error is made.
There are 6 GO (GameObject) one of which should become active (initially all are inactive) by pressing the button.
Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RNDElem : MonoBehaviour
{
public GameObject Air;
public GameObject Water;
public GameObject Ligth;
public GameObject Fire;
public GameObject Earth;
public GameObject Darkness;
 
 public void ActivateRandomObject(GameObject[] arrayOfGameObjects)
 
 {
     arrayOfGameObjects[Random.Range(0, arrayOfGameObjects.Length - 1)].SetActive(true);
}
}

The console does not give any errors. I tend to think that the error is in the script itself, or I somehow incorrectly added the script to the button. Please do not throw slippers, I'm just learning)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2020-09-20
@SHELLL90

Well, and the method is called somewhere? It is necessary to debug - the script is correct at first glance

V
VinyLaPuh, 2020-09-21
@VinyLaPuh

SHELLL90 Attach the screenshot how you attached the script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question