Skip to content

Instantly share code, notes, and snippets.

@GameDevTeacher
Last active April 22, 2016 11:43
Show Gist options
  • Save GameDevTeacher/0d0ae91679a28ce300bd6bc667f9bd87 to your computer and use it in GitHub Desktop.
Save GameDevTeacher/0d0ae91679a28ce300bd6bc667f9bd87 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System;
public class ObjectFade_Controller : MonoBehaviour {
[Header("Activated Objects")]
[Range(0,10)]
public int Activate_Size;
[Space(5)]
// Button Array
public Button [] _buttonActivate;
// Game Object Array
public GameObject [] _objectActivate;
// Private bool to check if object is active
private bool _isTrue = true;
private bool [] _isActive;
// Global bool array of which object has been clicked
public static bool [] _clicked_nr = new bool [24] {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
void Awake (){
#region ACTIVATE
//DECLARE ALL BOOLS IN ARRAY AS TRUE AT BIRTH OF OBJECT
for (int i = 0; i < _isActive.Length;i++)
{
if (!_isTrue)
break;
else
{
_isTrue = !_isActive[i];
}
if (_isTrue)
{
_isActive[i] = true;
}
}
#endregion
for (int i = 0; i<_isInactive.Length;i++){
_objectDeactivate[i].SetActive(false);
}
}
// Use this for initialization
void Start ()
{
#region ACTIVATE
for (int i=0; i< _buttonActivate.Length;i++)
{
int item = i;
_buttonActivate[item].onClick.AddListener(() => Nummer(item));
}
#endregion
}
// Update is called once per frame
void Update () {
#region ACTIVATE
for (int i = 0; i < _clicked_nr.Length && i < _isActive.Length;i++)
{
if (_clicked_nr[i])
{
if (_isActive[i])
{
_objectActivate[i].SetActive(false);
_isActive[i] = false;
} else {
_objectActivate[i].SetActive(true);
_isActive[i]= true;
}
_clicked_nr[i] = false;
}
}
#endregion
}
void Nummer (int i)
{
_clicked_nr[i] = true;
Debug.Log("Nummer"+i+"har blitt klikket på");
}
void OnValidate()
{
//ACTIVATE
Array.Resize(ref _buttonActivate, Activate_Size);
Array.Resize(ref _objectActivate, Activate_Size);
Array.Resize(ref _isActive, Activate_Size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment