Created
January 15, 2022 16:07
-
-
Save farukcan/b23716f35b81efeee3c53c0b2180fc12 to your computer and use it in GitHub Desktop.
Unity Code for enable next one of child of the game object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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