Unity3d 左右箭頭選人時左右箭頭出現機判斷

    List<EntryDate > PlayerEntryDateList =new List<EntryDate > ();

    int currIndex=0;
    GameObject currPlayerGo;
    EntryDate currPlayerDate;
    
    void UpdateUI()
    {

        int Count= PlayerEntryDateList.Count;
        if (Count-1  == currIndex || Count - 1 == 0 )
        {
            rightButton.gameObject.SetActive(false);
        }
        else
        {
            rightButton.gameObject.SetActive(true);
        }


        if(currIndex==0 || Count - 1 == 0 )
        {
            leftButton.gameObject.SetActive(false);
        }
        else
        {
            leftButton.gameObject.SetActive(true);
        }


    }
    
    GameObject CreatPlayer()
    {
       currPlayerDate = PlayerEntryDateList[currIndex];
        var playerGo =Instantiate(currPlayerDate.prefab);
        UpdateUI();
        return playerGo;
    }
    
    void leftButton_Click()
    {
        currIndex--;
        DestroyImmediate(currPlayerGo);
        currPlayerGo = CreatPlayer();
    }
    void rightButton_Click()
    {
        currIndex++;
        DestroyImmediate(currPlayerGo);
        currPlayerGo = CreatPlayer();
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章