Example #1
0
        public void Setup(SignalRManager manager)
        {
            // Get references to the components.
            m_Movement = m_Instance.GetComponent <TankMovement> ();
            m_Shooting = m_Instance.GetComponent <TankShooting> ();
            m_Health   = m_Instance.GetComponent <TankHealth>();

            m_Shooting.m_ConnectionManager = manager;
            m_Health.m_ConnectionManager   = manager;

            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas> ().gameObject;

            // Set the player numbers to be consistent across the scripts.
            m_Movement.m_PlayerNumber = m_PlayerNumber;
            m_Shooting.m_PlayerNumber = m_PlayerNumber;

            // Create a string using the correct color that says 'PLAYER 1' etc based on the tank's color and the player's number.
            m_ColoredPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + m_PlayerNumber + "</color>";

            // Get all of the renderers of the tank.
            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();

            // Go through all the renderers...
            for (int i = 0; i < renderers.Length; i++)
            {
                // ... set their material color to the color specific to this tank.
                renderers[i].material.color = m_PlayerColor;
            }
        }
Example #2
0
        private void Start()
        {
            mConnectionManager = new Complete.SignalRManager();
            mConnectionManager.OnActionTrack = (x, v, r) =>
            {
                if (m_Tanks[0].m_TankId == x /*&& _TankToTrack!=0*/)
                {
                    m_Tanks[0].m_Movement.SetLocation(v, r);
                }
                if (m_Tanks[1].m_TankId == x /*&& _TankToTrack != 1*/)
                {
                    m_Tanks[1].m_Movement.SetLocation(v, r);
                }
            };

            mConnectionManager.OnActionFire = (p, r, v) => {
                m_Tanks[1].m_Shooting.ExecFire(p, r, v);
            };

            mConnectionManager.OnStartSession = (list) =>
            {
                foreach (GameSessionPlayerItem i in list)
                {
                    TankManager tm = m_Tanks[i.Sequence - 1];
                    tm.m_AssociatedUserId = i.UserId;
                    tm.m_TankId           = i.TankId;
                    if (i.UserId == mConnectionManager._UserId)
                    {
                        tm.SetColor(Color.green);
                    }
                }
                hasSession = true;
            };

            mConnectionManager.OnActionSetDamage = (tankId, amount) =>
            {
                if (m_Tanks[0].m_TankId == tankId)
                {
                    m_Tanks[0].SetDamage(amount);
                }
                if (m_Tanks[1].m_TankId == tankId)
                {
                    m_Tanks[1].SetDamage(amount);
                }
            };

            mConnectionManager.OnRoundBegins = (roundno) =>
            {
                remoteRoundNo = roundno;
                canStartRound = true;
            };

            StartCoroutine(Connect());

            // Create the delays so they only have to be made once.
            m_StartWait = new WaitForSeconds(m_StartDelay);
            m_EndWait   = new WaitForSeconds(m_EndDelay);

            SpawnAllTanks();
            SetCameraTargets();

            // Once the tanks have been created and the camera is using them as targets, start the game.
            StartCoroutine(GameLoop());
        }