Esempio n. 1
0
        public void Setup()
        {
            // Get references to the child objects.
            m_TankRenderers  = m_Instance.transform.Find("TankRenderers").gameObject;
            m_HealthCanvas   = m_Instance.transform.Find("HealthCanvas").gameObject;
            m_AimCanvas      = m_Instance.transform.Find("AimCanvas").gameObject;
            m_LeftDustTrail  = m_Instance.transform.Find("LeftDustTrail").gameObject;
            m_RightDustTrail = m_Instance.transform.Find("RightDustTrail").gameObject;

            // Get references to the components.
            m_Movement = m_Instance.GetComponent <TankMovement> ();
            m_Shooting = m_Instance.GetComponent <TankShooting> ();
            m_Health   = m_Instance.GetComponent <TankHealth> ();
            m_Collider = m_Instance.GetComponent <BoxCollider> ();

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

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

            // 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;
            }
        }
Esempio n. 2
0
    void Start()
    {
        _navAgent  = GetComponent <NavMeshAgent>();
        _tMovement = gameObject.GetComponent <Complete.TankMovement>();
        _tShooting = gameObject.GetComponent <Complete.TankShooting>();

        if (gameObject.CompareTag("Player1"))
        {
            if (GameObject.FindGameObjectWithTag("Player2") != null)
            {
                _enemyTank = GameObject.FindGameObjectWithTag("Player2");
            }
            else
            {
                //Debug.Log("No Object with tag 'Player2'");
            }
        }
        else
        {
            if (GameObject.FindGameObjectWithTag("Player1") != null)
            {
                _enemyTank = GameObject.FindGameObjectWithTag("Player1");
            }
            else
            {
                //Debug.Log("No Object with tag 'Player1'");
            }
        }

        InitializeTank();
    }
Esempio n. 3
0
 void Awake()
 {
     tankShooting     = GetComponent <Complete.TankShooting> ();
     tankHealth       = GetComponent <Complete.TankHealth> ();
     navMeshAgent     = GetComponent <NavMeshAgent> ();
     recoveryDisabled = false;
 }
Esempio n. 4
0
    void UpdateTarget()
    {
        float      shortestDistance = Mathf.Infinity;
        GameObject nearestEnemy     = null;

        foreach (GameObject e in _enemy)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, e.transform.position);

            Complete.TankShooting t = e.gameObject.GetComponent <Complete.TankShooting>();
            if (t != null)
            {
                if (distanceToEnemy < shortestDistance && playerNumber != e.GetComponent <Complete.TankShooting>().m_PlayerNumber)
                {
                    shortestDistance = distanceToEnemy;
                    nearestEnemy     = e;
                }
            }
        }


        if (nearestEnemy != null && shortestDistance <= range && target != nearestEnemy.transform)
        {
            target = nearestEnemy.transform;
            reloadAudio.Play();
        }
        else if (shortestDistance > range)
        {
            target = null;
        }
    }
Esempio n. 5
0
        public void SetupPlayerTank(CameraControl cameraControl)
        {
            // Get references to the components.

            m_Movement         = m_Instance.GetComponent <TankMovement>();
            m_Shooting         = m_Instance.GetComponent <TankShooting>();
            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;
            }

            // This is the player tank, so focus the camera on it.
            var sfc = cameraControl.GetComponent <SimpleFollowCamera>();

            if (sfc != null)
            {
                sfc.followTarget = m_Instance.transform;
            }
        }
Esempio n. 6
0
        public void Setup()
        {
            // Get references to the components.
            m_Movement = m_Instance.GetComponent<TankMovement> ();
            m_Shooting = m_Instance.GetComponent<TankShooting> ();
            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;

            string tank = "PLAYER[" + m_PlayerNumber + "]";

            TankAI tankAI = m_Instance.GetComponent<TankAI>();

            if (tankAI) tank = tankAI.tankName + "[" + 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) + "> "+ tank + "</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;
            }
        }
Esempio n. 7
0
        public void Setup()
        {
            // Get references to the components.
            m_Movement         = m_Instance.GetComponent <TankMovement>();
            m_Shooting         = m_Instance.GetComponent <TankShooting>();
            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas>().gameObject;
            m_NameText         = m_Instance.GetComponentInChildren <Text>();

            // 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;
            }
        }
Esempio n. 8
0
        void Awake()
        {
            tankMover = GetComponent<TankMovement>();
            tankNav = GetComponent<TankNavigation>();
            tankSensor = GetComponentInChildren<TankSensor>();
            tankShooter = GetComponent<TankShooting>();
            tankHealth = GetComponent<TankHealth>();

            Reset();
        }
 ///</TankHealt>
 ///<TankShooting>
 void Serialize(NetworkWriter _writer, Complete.TankShooting shot)
 {
     _writer.Write(shot.m_LastLaunchForce);
     _writer.Write(shot.m_CurrentLaunchForce);
     _writer.Write(shot.m_Fired);
     if (shot.m_Fired)
     {
         _writer.Write(shot.m_FireTransform.position);
         _writer.Write(shot.m_FireTransform.rotation);
     }
 }
 public override void InitializeAgent()
 {
     tankMovement = GetComponent <TankMovement>();
     tankShooting = GetComponent <TankShooting>();
     base.InitializeAgent();
     agentRb = GetComponent <Rigidbody>();
     Monitor.verticalOffset = 1f;
     //myArea = area.GetComponent<BananaArea>();
     rayPer = GetComponent <RayPerception>();
     //myAcademy = myAcademyObj.GetComponent<BananaAcademy>();
 }
Esempio n. 11
0
        public void SetupPlayerTank()
        {
            m_Movement         = m_Instance.GetComponent <TankMovement> ();
            m_Shooting         = m_Instance.GetComponent <TankShooting> ();
            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas> ().gameObject;

            m_Movement.m_PlayerNumber = m_PlayerNumber;
            m_Shooting.m_PlayerNumber = m_PlayerNumber;

            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();
        }
Esempio n. 12
0
        public void SetupAI(List <Transform> wayPointList)
        {
            m_StateController = m_Instance.GetComponent <StateController> ();
            m_StateController.SetupAI(true, wayPointList);

            m_Shooting = m_Instance.GetComponent <TankShooting> ();
            m_Shooting.m_PlayerNumber = m_PlayerNumber;

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

            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();
        }
Esempio n. 13
0
        protected abstract void SetName(); // all AI's should set their name - please use Unity forum name

        protected void Awake()
        {
            SetName();

            tankMover   = GetComponent <TankMovement>();
            tankNav     = GetComponent <TankNavigation>();
            tankSensor  = GetComponentInChildren <TankSensor>();
            tankShooter = GetComponent <TankShooting>();
            tankHealth  = GetComponent <TankHealth>();

            Reset();
        }
Esempio n. 14
0
        public void Start()
        {
            tankMover = GetComponent<TankMovement>();
            tankNav = GetComponent<NavMeshAgent>();
            tankSensor = GetComponentInChildren<TankSensor>();
            tankShooter = GetComponent<TankShooting>();
            tankHealth = GetComponent<TankHealth>();

            moveToMarker.SetParent(null);

            Reset();
        }
Esempio n. 15
0
        // Start behaviour tree
        private void Start()
        {
            m_Movement = GetComponent <TankMovement> ();
            m_Shooting = GetComponent <TankShooting> ();

            tree       = CreateBehaviourTree();
            blackboard = tree.Blackboard;
            #if UNITY_EDITOR
            Debugger debugger = (Debugger)this.gameObject.AddComponent(typeof(Debugger));
            debugger.BehaviorTree = tree;
            #endif

            tree.Start();
        }
    void Deserialize(NetworkReader _reader, Complete.TankShooting shot)
    {
        float lastLaunchForce = _reader.ReadSingle();

        shot.m_CurrentLaunchForce = _reader.ReadSingle();
        if (_reader.ReadBoolean() && lastLaunchForce != shot.m_LastLaunchForce)
        {
            shot.m_FireTransform.position = _reader.ReadVector3();
            shot.m_FireTransform.rotation = _reader.ReadQuaternion();
            shot.m_CurrentLaunchForce     = lastLaunchForce;
            shot.Fire();
            shot.m_Fired = false;
        }
    }
Esempio n. 17
0
        private GameObject m_CanvasGameObject;                  // Used to disable the world space UI during the Starting and Ending phases of each round



        void Start()
        {
            // Get references to the components
            m_Movement         = GetComponent <TankMovement> ();
            m_Shooting         = GetComponent <TankShooting> ();
            m_CanvasGameObject = GetComponentInChildren <Canvas> ().gameObject;

            Label = gameObject.transform.GetChild(5).GetChild(0).GetComponent <Text>();


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

            FindObjectOfType <GameManager>().m_Tanks.Add(this);
        }
Esempio n. 18
0
        // Start behaviour tree
        private void Start()
        {
            Debug.Log("Initialising AI player " + m_PlayerNumber);
            m_Movement = GetComponent <TankMovement> ();
            m_Shooting = GetComponent <TankShooting> ();
            m_Health   = GetComponent <TankHealth>();

            tree       = CreateBehaviourTree();
            blackboard = tree.Blackboard;
            #if UNITY_EDITOR
            Debugger debugger = (Debugger)this.gameObject.AddComponent(typeof(Debugger));
            debugger.BehaviorTree = tree;
            #endif

            tree.Start();
        }
Esempio n. 19
0
        public void SetupAITurret()
        {
            m_StateController = m_Instance.GetComponent <StateController>();
            m_StateController.SetupAITurret(true);

            m_Shooting = m_Instance.GetComponent <TankShooting>();
            m_Shooting.m_PlayerNumber = m_EnemyTurretNumber;

            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_EnemyTurretColor;
            }
        }
Esempio n. 20
0
        public void Setup()
        {
            ToggleSounds(false);

            _movement  = _instance.GetComponent <TankMovement>();
            _shooting  = _instance.GetComponent <TankShooting>();
            _health    = _instance.GetComponent <TankHealth>();
            _explosion = _instance.GetComponent <ShellExplosion>();

            _canvasGameObject = _instance.GetComponentInChildren <Canvas>().gameObject;

            _movement._playerNumber = _playerNumber;
            _shooting._playerNumber = _playerNumber;

            MeshRenderer[] renderers = _instance.GetComponentsInChildren <MeshRenderer>();
            renderers.ToList().ForEach(x => x.material.color = _playerColor);
        }
Esempio n. 21
0
        public void SetupPlayerTank()
        {
            m_Movement         = m_Instance.GetComponent <TankMovement> ();
            m_Shooting         = m_Instance.GetComponent <TankShooting> ();
            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas> ().gameObject;

            m_Movement.m_PlayerNumber = m_PlayerNumber;
            m_Shooting.m_PlayerNumber = m_PlayerNumber;
            m_ColoredPlayerText       = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + m_PlayerNumber + "</color>";

            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();

            for (int i = 0; i < renderers.Length; i++)
            {
                renderers[i].material.color = m_PlayerColor;
            }
        }
Esempio n. 22
0
        public void Setup()
        {
            // Get references to the components.
            m_Movement         = m_Instance.GetComponent <TankMovement>();
            m_Shooting         = m_Instance.GetComponent <TankShooting>();
            m_Health           = m_Instance.GetComponent <TankHealth>();
            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas>().gameObject;
            m_TankName         = m_Instance.AddComponent <TankName>();

            // Set the player numbers to be consistent across the scripts.
            m_Movement.m_PlayerNumber = m_PlayerNumber;
            m_Movement.m_LoaclId      = m_LocalPlayerId;
            m_Movement.isLocalPlayer  = isLocalPlayer;

            m_Shooting.m_PlayerNumber = m_PlayerNumber;
            m_Shooting.m_LoaclId      = m_LocalPlayerId;
            m_Shooting.isLocalPlayer  = isLocalPlayer;

            m_Health.isLocalPlayer = isLocalPlayer;

            m_Instance.name       = "Player-" + m_LocalPlayerId;
            m_TankName.playerName = m_Instance.name;

            if (isLocalPlayer)
            {
                //Camera.main.GetComponent<CameraFollow>().player = m_Instance.transform;
                m_Shooting.ShootEvent += M_Shooting_ShootEvent;
                m_Health.HealthEvent  += M_Health_HealthEvent;
            }

            // 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) + "> " + m_Instance.name + "</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;
            }
        }
Esempio n. 23
0
        private void SpawnAllTanks()
        {
            // For all the tanks...
            for (int i = 0; i < m_Tanks.Length; i++)
            {
                // ... create them, set their player number and references needed for control.
                m_Tanks[i].m_Instance =
                    Instantiate(m_TankPrefab, m_Tanks[i].m_SpawnPoint.position, m_Tanks[i].m_SpawnPoint.rotation) as GameObject;
                TankShooting tankShooting = m_Tanks[i].m_Instance.GetComponent <TankShooting>();
                m_Tanks[i].m_PlayerNumber = i + 1;
                (m_Tanks[i].m_Instance.GetComponent <GravityMass>()).Attractor = this.Ground;
                (tankShooting.m_Shell.GetComponent <GravityMass>()).Attractor  = this.Ground;

                // Abandoned: Code for calculating the speed necessary to put a shot in a uniform circular orbit
                //float shotRadius = (this.Ground.transform.lossyScale.y / 2.0f + tankShooting.m_FireTransform.position.y);
                //// tankShooting.m_MaxLaunchForce = shotRadius * Mathf.Sqrt(-this.Ground.Gravity / Mathf.Pow(shotRadius, 3));
                //tankShooting.m_MaxLaunchForce = shotRadius / 2;
                m_Tanks[i].Setup();
            }
        }
Esempio n. 24
0
        public void SetupAI(List <Transform> wayPointList)
        {
            m_StateController = m_Instance.GetComponent <StateController> ();
            m_StateController.SetupAI(true, wayPointList);

            m_Shooting = m_Instance.GetComponent <TankShooting> ();
            m_Shooting.m_PlayerNumber = m_PlayerNumber;

            m_CanvasGameObject  = m_Instance.GetComponentInChildren <Canvas> ().gameObject;
            m_ColoredPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + m_PlayerNumber + "</color>";


            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();


            for (int i = 0; i < renderers.Length; i++)
            {
                renderers[i].material.color = m_PlayerColor;
            }
        }
Esempio n. 25
0
    void setupTank(Transform tank, float patateColor, int num)
    {
        MeshRenderer[] renderers = tank.GetComponentsInChildren <MeshRenderer>();

        // Go through all the renderers...
        Color color = Color.HSVToRGB(patateColor, patateColor, patateColor);

        for (int i = 0; i < renderers.Length; i++)
        {
            // ... set their material color to the color specific to this tank.
            renderers[i].material.color = color;
        }

        Complete.TankMovement mvt = tank.GetComponent <Complete.TankMovement>();
        Complete.TankShooting sht = tank.GetComponent <Complete.TankShooting>();

        // Set the player numbers to be consistent across the scripts.
        mvt.m_PlayerNumber = num;
        sht.m_PlayerNumber = num;
    }
Esempio n. 26
0
        private GameObject m_CanvasGameObject;                  // Used to disable the world space UI during the Starting and Ending phases of each round.


        public void Setup()
        {
            // Get references to the components.
            m_Movement         = m_Instance.GetComponent <TankMovement> ();
            m_Shooting         = m_Instance.GetComponent <TankShooting> ();
            m_Health           = m_Instance.GetComponent <TankHealth> ();
            m_Colour           = m_Instance.GetComponent <TankColour> ();
            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;
            m_Colour.m_PlayerNumber   = m_PlayerNumber;

            m_Colour.m_HUDIcon = m_HUDIcon;
            m_Health.m_Slider  = m_HUDSlider;
            m_Health.m_anim    = m_anim;

            SetColour(m_PlayerColor);
        }
Esempio n. 27
0
		private GameObject m_CanvasGameObject;                  // Used to disable the world space UI during the Starting and Ending phases of each round.


		public void Setup ()
		{
			// Get references to the components.
			m_Movement = m_Instance.GetComponent<TankMovement> ();
			m_Shooting = m_Instance.GetComponent<TankShooting> ();
			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;

			// Get all of the renderers of the bot.
			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 bot.
				renderers[i].material.color = m_BotColor;
			}
		}
Esempio n. 28
0
        private GameObject m_CanvasGameObject;                  // Used to disable the world space UI during the Starting and Ending phases of each round.


        public void Setup()
        {
            // Get references to the components.
            m_Movement         = m_Instance.GetComponent <TankMovement> ();
            m_Shooting         = m_Instance.GetComponent <TankShooting> ();
            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;

            // 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 = color;
            }
        }
Esempio n. 29
0
        public void SetupAI(List <Transform> wayPointList)
        {
            m_StateController = m_Instance.GetComponent <StateController>();
            m_StateController.SetupAI(true, wayPointList);

            m_Shooting = m_Instance.GetComponent <TankShooting>();
            m_Shooting.m_PlayerNumber = m_EnemyNumber;

            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas>().gameObject;
            //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_EnemyColor;
            }
        }
Esempio n. 30
0
    // Update is called once per frame
    void Update()
    {
        if (target == null)
        {
            return;
        }
        man.SetDestination(target.position);

        if (Vector3.Distance(target.position, transform.position) > 20)
        {
            return;
        }

        count = count + 1;
        if (count < 10)
        {
            return;
        }
        count = 0;

        Ray        ray = new Ray(transform.position, target.position);
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit))
        {
            Debug.Log(hit.transform.gameObject.name);
            if (!(hit.transform.gameObject.name == target.gameObject.name))
            {
                return;
            }
        }

        Complete.TankShooting mono          = gameObject.GetComponent <Complete.TankShooting> ();
        Rigidbody             shellInstance =
            Instantiate(mono.m_Shell, mono.m_FireTransform.position, mono.m_FireTransform.rotation) as Rigidbody;

        shellInstance.velocity    = mono.m_MinLaunchForce * mono.m_FireTransform.forward;
        mono.m_ShootingAudio.clip = mono.m_FireClip;
        mono.m_ShootingAudio.Play();
    }
Esempio n. 31
0
        private GameObject m_CanvasGameObject;                  // Used to disable the world space UI during the Starting and Ending phases of each round.

        public void Setup(Transform[] checkpoints)
        {
            // Reset the laps and his value in the UI dial
            m_Laps         = 0;
            m_LapDial.text = string.Empty;

            // Get references to the components.
            m_Movement         = m_Instance.GetComponent <TankMovement>();
            m_Shooting         = m_Instance.GetComponent <TankShooting>();
            m_Compass          = m_Instance.GetComponent <TankCompass>();
            m_TankStatus       = m_Instance.GetComponent <TankStatus>();
            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;
            m_Compass.m_PlayerNumber    = m_PlayerNumber;
            m_TankStatus.m_PlayerNumber = m_PlayerNumber;

            //Set the player colors for the UI
            m_Compass.m_PlayerColor    = m_PlayerColor;
            m_TankStatus.m_PlayerColor = m_PlayerColor;

            // 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;
            }

            //Set all the checkpoints to be reached
            m_Compass.SetCheckpoints(checkpoints);
        }
Esempio n. 32
0
        private GameObject m_CanvasGameObject;                  // 显示蓄力的箭头UI


        public void Setup()
        {
            // 通过物体获取组件
            m_Movement         = m_Instance.GetComponent <TankMovement> ();
            m_Shooting         = m_Instance.GetComponent <TankShooting> ();
            m_CanvasGameObject = m_Instance.GetComponentInChildren <Canvas> ().gameObject;

            // 设置坦克的编号,用来区分不同的移动和开火键

            // 一个带有颜色的字符串用来显示文字,颜色和坦克的颜色一样
            m_ColoredPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + "</color>";

            // 获取坦克的子物体身上的渲染组件
            MeshRenderer[] renderers = m_Instance.GetComponentsInChildren <MeshRenderer> ();

            // 遍历所有取得的子物体的渲染组件
            for (int i = 0; i < renderers.Length; i++)
            {
                // 给它的子物体的材质赋指定颜色
                renderers[i].material.color = m_PlayerColor;
            }
        }
        private void SpawnAllTanks()
        {
            // For all the tanks...
            for (int i = 0; i < m_Tanks.Length; i++)
            {
                var ran = Random.Range(0, 180);
                var rot = Quaternion.Euler(0, ran, 0);

                // ... create them, set their player number and references needed for control.
                m_Tanks[i].m_Instance =
                    Instantiate(m_TankPrefab, m_Tanks[i].m_SpawnPoint.position, rot) as GameObject;
                m_Tanks[i].m_Instance.transform.localRotation = rot;
                m_Tanks[i].m_PlayerNumber = i + 1;
                m_Tanks[i].Setup();
            }

            var instance = m_Tanks[0].m_Instance;

            m_Player1Movement = instance.GetComponent <TankMovement>();
            m_Player1Shooting = instance.GetComponent <TankShooting>();
            m_Player1Health   = instance.GetComponent <TankHealth>();
        }
Esempio n. 34
0
 void Awake()
 {
     tankShooting = GetComponent <Complete.TankShooting> ();
     navMeshAgent = GetComponent <NavMeshAgent> ();
 }