コード例 #1
0
 void SetPlayerLocks(bool aState)
 {
     // tell all of the players to set their locks
     for (int i = 0; i < numberOfBattlers; i++)
     {
         thePlayerScript = ( CarController_TB )playerList [i];
         thePlayerScript.SetLock(aState);
     }
 }
コード例 #2
0
    void Init()
    {
        if (playerList != null)
        {
            Debug.ClearDeveloperConsole();
            Debug.Log("playerList.Count =" + playerList.Count);
            Debug.Break();
        }

        SpawnController.Instance.Restart();

        // incase we need to change the timescale, it gets set here
        Time.timeScale = gameSpeed;

        // tell battle manager to prepare for the battle
        GlobalBattleManager.Instance.InitNewBattle();

        // initialize some temporary arrays we can use to set up the players
        Vector3 []    playerStarts    = new Vector3 [numberOfBattlers];
        Quaternion [] playerRotations = new Quaternion [numberOfBattlers];

        // we are going to use the array full of start positions that must be set in the editor, which means we always need to
        // make sure that there are enough start positions for the number of players

        for (int i = 0; i < numberOfBattlers; i++)
        {
            // grab position and rotation values from start position transforms set in the inspector
            playerStarts [i]    = (Vector3)startPoints [i].position;
            playerRotations [i] = ( Quaternion )startPoints [i].rotation;
        }

        SpawnController.Instance.SetUpPlayers(playerPrefabList, playerStarts, playerRotations, playerParent, numberOfBattlers);

        playerTransforms = new ArrayList();

        // now let's grab references to each player's controller script
        playerTransforms = SpawnController.Instance.GetAllSpawnedPlayers();

        playerList = new ArrayList();

        for (int i = 0; i < numberOfBattlers; i++)
        {
            Transform        tempT          = (Transform)playerTransforms[i];
            CarController_TB tempController = tempT.GetComponent <CarController_TB>();

            playerList.Add(tempController);

            BaseAIController tempAI = tempController.GetComponent <BaseAIController>();

            tempController.Init();

            if (i > 0)
            {
                // grab a ref to the player's gameobject for later
                playerGO1 = SpawnController.Instance.GetPlayerGO(0);

                // tell AI to get the player!
                tempAI.SetChaseTarget(playerGO1.transform);

                // set AI mode to chase
                tempAI.SetAIState(AIStates.AIState.steer_to_target);
            }
        }

        // add an audio listener to the first car so that the audio is based from the car rather than the main camera
        playerGO1.AddComponent <AudioListener>();

        // look at the main camera and see if it has an audio listener attached
        AudioListener tempListener = Camera.main.GetComponent <AudioListener>();

        // if we found a listener, let's destroy it
        if (tempListener != null)
        {
            Destroy(tempListener);
        }

        // grab a reference to the focussed player's car controller script, so that we can
        // do things like access its speed variable
        thePlayerScript = ( CarController_TB )playerGO1.GetComponent <CarController_TB>();

        // assign this player the id of 0 - this is important. The id system is how we will know who is firing bullets!
        thePlayerScript.SetID(0);

        // set player control
        thePlayerScript.SetUserInput(true);

        // as this is the user, we want to focus on this for UI etc.
        focusPlayerScript = thePlayerScript;

        // tell the camera script to target this new player
        cameraScript.SetTarget(playerGO1.transform);

        // lock all the players on the spot until we're ready to go
        SetPlayerLocks(true);

        // start the game in 3 seconds from now
        Invoke("StartGame", 4);

        // initialize a timer, but we won't start it right away. It gets started in the FinishedCount() function after the count-in
        theTimer = ScriptableObject.CreateInstance <TimerClass>();

        // update positions throughout the battle, but we don't need
        // to do this every frame, so just do it every half a second instead
        InvokeRepeating("UpdatePositions", 0f, 0.5f);

        // hide our count in numbers
        HideCount();

        // schedule count in messages
        Invoke("ShowCount3", 1);
        Invoke("ShowCount2", 2);
        Invoke("ShowCount1", 3);
        Invoke("FinishedCount", 4);

        // hide final position text
        finalPositionText.gameObject.SetActive(false);
        doneFinalMessage = false;

        didInit = true;
    }