You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
835 B
33 lines
835 B
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class ButtonFocus : MonoBehaviour |
|
{ |
|
public List<ButtonFocusItem> listbfItem; |
|
public int idx = 0; |
|
|
|
void Start() |
|
{ |
|
listbfItem[idx].Focus(); |
|
} |
|
void Update() |
|
{ |
|
if(Input.GetKeyDown(KeyCode.DownArrow)) |
|
{ |
|
listbfItem[idx].Focus(false); |
|
idx = idx + 1 < listbfItem.Count ? idx + 1 : 0; |
|
listbfItem[idx].Focus(true); |
|
} |
|
else if(Input.GetKeyDown(KeyCode.UpArrow)) |
|
{ |
|
listbfItem[idx].Focus(false); |
|
idx = -1 < idx - 1 ? idx - 1 : listbfItem.Count - 1; |
|
listbfItem[idx].Focus(true); |
|
} |
|
else if(Input.GetKeyDown(KeyCode.Return)) |
|
{ |
|
listbfItem[idx].OnFocusSelect(); |
|
} |
|
} |
|
}
|
|
|