Exemple #1
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();
    }
        // Reference to the StateController for AI tanks
        // Use this for initialization

        public void SetupPlayerTank()
        {
            // 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_CanvasGameObject.SetActive(false);
            // Set the player numbers to be consistent across the scripts.
            m_Movement.m_PlayerNumber = 1;
            m_Shooting.m_PlayerNumber = 1;

            // 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;
            }
        }
Exemple #3
0
        private void Start()
        {
            agent    = GetComponent <NavMeshAgent>();
            animator = GetComponent <Animator>();

            tankMovement = GetComponent <TankMovement>();
        }
Exemple #4
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;
            }
        }
Exemple #5
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;
            }
        }
Exemple #6
0
 public void OnTriggerExit(Collider other)
 {
     if (other.gameObject.CompareTag("Tank"))
     {
         TankMovement tankMovement = other.GetComponent <TankMovement>();
         tankMovement.m_Speed = 15;
     }
 }
Exemple #7
0
        void Awake()
        {
            tankMover = GetComponent<TankMovement>();
            tankNav = GetComponent<TankNavigation>();
            tankSensor = GetComponentInChildren<TankSensor>();
            tankShooter = GetComponent<TankShooting>();
            tankHealth = GetComponent<TankHealth>();

            Reset();
        }
Exemple #8
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> ();
        }
 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>();
 }
Exemple #10
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();
        }
Exemple #11
0
        public void Start()
        {
            tankMover = GetComponent<TankMovement>();
            tankNav = GetComponent<NavMeshAgent>();
            tankSensor = GetComponentInChildren<TankSensor>();
            tankShooter = GetComponent<TankShooting>();
            tankHealth = GetComponent<TankHealth>();

            moveToMarker.SetParent(null);

            Reset();
        }
Exemple #12
0
        void Awake()
        {
            // Set up the references.

            //player = GameObject.Find("Player").transform;
            //playerHealth  = players.GetComponent<TankHealth>();
            enemyHealth = GetComponent <NPCHealth>();
            nav         = GetComponent <NavMeshAgent>();

            //EnemyAnim = GetComponent<Animator>();

            PlayerMovScript = FindObjectOfType <TankMovement>();
        }
Exemple #13
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();
        }
Exemple #14
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);
        }
Exemple #15
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();
        }
Exemple #16
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;
            }
        }
Exemple #17
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);
        }
Exemple #18
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;
            }
        }
    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;
    }
Exemple #20
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);
        }
		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;
			}
		}
Exemple #22
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;
            }
        }
Exemple #23
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>();
        }
Exemple #25
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);
        }
Exemple #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>();

            foreach (Canvas canvas in m_Instance.GetComponentsInChildren <Canvas>())
            {
                if (canvas.name == "NicknameCanvas")
                {
                    m_NicknameCanvas = canvas.gameObject;
                    m_NicknameText   = canvas.gameObject.GetComponentInChildren <Text>();
                }
                else
                {
                    m_CanvasGameObject = canvas.gameObject;
                }
            }

            m_NicknameText.text = m_Nickname;

            // 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) + "> " + m_Nickname + "</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;
            }
        }
Exemple #27
0
using System; using UnityEngine; namespace Complete { [Serializable] public class TankManager { public Color m_PlayerColor; public Transform m_SpawnPoint; [HideInInspector] public int m_PlayerNumber; [HideInInspector] public string m_ColoredPlayerText; [HideInInspector] public GameObject m_Instance; [HideInInspector] public int m_Wins; private TankHealth m_Health; private TankMovement m_Movement; private TankShooting m_Shooting; private GameObject m_CanvasGameObject; public void Setup()
                                                                                                {
                                                                                                    System.Random ran = new System.Random(); float random = ran.Next(1, 200); m_Health = m_Instance.GetComponent <TankHealth>(); 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_Shooting.m_MaxChargeTime = 0.7f;
                                                                                                    m_Movement.m_Speed         = 2f;
                                                                                                    m_Health.m_StartingHealth  = 400f;
                                                                                                    m_Shooting.m_MaxChargeTime = random;
                                                                                                    m_Movement.m_Speed         = random;
                                                                                                    m_Health.m_StartingHealth  = random;
                                                                                                    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;
                                                                                                    }
                                                                                                }
Exemple #28
0
 // Use this for initialization
 void Start()
 {
     tm = GetComponent <Complete.TankMovement>();
     ts = GetComponent <Complete.TankShooting>();
 }
Exemple #29
0
 // Start is called before the first frame update
 void Start()
 {
     tank = transform.parent.gameObject.GetComponent <Complete.TankMovement>();
 }