コード例 #1
0
    public void assignListener()
    {
        if (!allAssigned)
        { //check if all button have been assigned or not
            if (GameManager.instance.players.Length > 0)
            {
                PlayerController player = GameManager.instance.GetPlayer(PhotonNetwork.NickName);
                if (player)
                {
                    resumeButton.onClick.AddListener(delegate { player.Resume(); });
                    pauseButton.onClick.AddListener(delegate { player.Pause(); });

                    // assign all action buttons after the player exist in the game
                    foreach (Transform child in player.transform)
                    {
                        BotController botScript = child.GetComponent <BotController>();
                        moveButton.onClick.AddListener(delegate { botScript.Move(); });
                        attackButton.onClick.AddListener(delegate { botScript.Attack(); });
                        guardButton.onClick.AddListener(delegate { botScript.Guard(); });
                        specialAbilitiesButton.onClick.AddListener(delegate { botScript.Abilities(); });
                    }

                    doubleDamage.onClick.AddListener(delegate {
                        if (player.Turn && !player.doubleDamageUsed)
                        {
                            player.DoubleDamage();
                            player.doubleDamageUsed = true;
                        }
                    });

                    timeStop.onClick.AddListener(delegate {
                        if (player.Turn && !player.timeStopUsed)
                        {
                            player.StopTime();
                            player.timeStopUsed = true;
                        }
                    });

                    randomPowerup.onClick.AddListener(delegate {
                        if (player.Turn && !player.randomUsed)
                        {
                            player.RandomPowerups();
                            player.randomUsed = true;
                        }
                    });
                    assignEventTrigger(player);

                    allAssigned = true;
                }
            }
        }
    }