Skip to content

Instantly share code, notes, and snippets.

@farukcan
Created January 15, 2022 16:07
Show Gist options
  • Save farukcan/b23716f35b81efeee3c53c0b2180fc12 to your computer and use it in GitHub Desktop.
Save farukcan/b23716f35b81efeee3c53c0b2180fc12 to your computer and use it in GitHub Desktop.
Unity Code for enable next one of child of the game object
// Author: github.com/farukcan
// Depends to Child Selector : https://gist.github.com/farukcan/cb7865963f59d4e3e6451a11dfcc0f3a
// Usage :
// list.Next()
// list.Back();
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NextBackList : ChildSelector {
public void Next() {
bool next = false;
Transform first = null;
foreach (Transform child in transform)
{
if (first == null)
first = child;
if (next) {
Select(child.gameObject.name);
return;
}
if (child.gameObject.activeSelf)
{
next = true;
}
}
Select(first.gameObject.name);
}
public void Back()
{
Transform pre = null;
foreach (Transform child in transform)
{
if (child.gameObject.activeSelf)
{
if (pre != null) {
Select(pre.gameObject.name);
return;
}
}
pre = child;
}
Select(pre.gameObject.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment