void Start() { tr = GetComponent <RectTransform>(); //싱글톤할당 instance = this; }
/// <summary> /// Handles the target switch - targets are sorted by their x-position. /// </summary> /// <param name="moveBy">Move by (-1 means left, 1 means right).</param> void handleTargetSwitch(TargetDirection moveBy) { var enemies = GameObject.FindGameObjectsWithTag("Hostile"); //Order by x-coord so first index is lowest x-coord List <GameObject> list = new List <GameObject>(enemies); list.Sort(((GameObject x, GameObject y) => Mathf.CeilToInt(x.transform.position.x - y.transform.position.x))); if (target == null) { if (list.Count > 0) { target = list [0]; placeArrow(); } } else { //Remove old arrow Destroy(arrow); int currIndex = list.FindIndex((GameObject obj) => obj == target); int nextIndex = Mathf.Abs((currIndex + (int)moveBy) % list.Count); target = list [nextIndex]; placeArrow(); } }