Ejemplo n.º 1
0
 void Awake()
 {
     tankShooting     = GetComponent <Complete.TankShooting> ();
     tankHealth       = GetComponent <Complete.TankHealth> ();
     navMeshAgent     = GetComponent <NavMeshAgent> ();
     recoveryDisabled = false;
 }
Ejemplo n.º 2
0
        void TankCollide(Collider[] tankColliders)
        {
            // Go through all the colliders...
            for (int i = 0; i < tankColliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = tankColliders[i].GetComponent <Rigidbody>();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Calculate the amount of damage the target should take based on it's distance from the shell.
                float damage = CalculateDamage(targetRigidbody.position);

                // Deal this damage to the tank.
                targetHealth.TakeDamage(damage);
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        private void OnTriggerEnter(Collider other)
        {
            // 以碰撞到的地方为中心,上面定义的半径球体内所有在tank层里的物体的collider集合
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);
            // 遍历这些碰撞器组件
            if (other.tag == "Player1")
            {
                // 获取Health组件
                TankHealth targetHealth = targetRigidbody2.GetComponent <TankHealth>();
                float      damage       = CalculateDamage(targetRigidbody2.transform.position);
                // 调用坦克身上的控制生命值的脚本来改变生命
                targetHealth.TakeDamage(damage);
            }

            // 脱离父子层级关系
            m_ExplosionParticles.transform.parent = null;

            // 播放粒子动画
            m_ExplosionParticles.Play();

            // 播放爆炸声音
            m_ExplosionAudio.Play();

            // 粒子动画播放完毕以后就销毁这个爆炸物体
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);

            // 销毁炮弹
            Destroy(gameObject);
        }
Ejemplo n.º 5
0
        private void OnTriggerEnter(Collider other)
        {
            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
            Collider[] colliders = Physics.OverlapSphere(transform.position, _explosionRadius, _tankMask);

            for (int i = 0; i < colliders.Length; i++)
            {
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
                if (!targetRigidbody)
                {
                    continue;
                }

                targetRigidbody.AddExplosionForce(_explosionForce, transform.position, _explosionRadius);


                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();
                if (!targetHealth)
                {
                    continue;
                }

                float damage = CalculateDamage(targetRigidbody.position);
                targetHealth.TakeDamage(damage);
            }

            _explosionParticles.transform.parent = null;
            _explosionParticles.Play();
            _explosionAudio.Play();

            ParticleSystem.MainModule mainModule = _explosionParticles.main;
            Destroy(_explosionParticles.gameObject, mainModule.duration);

            Destroy(gameObject);
        }
Ejemplo 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;
            health             = m_Instance.GetComponent <TankHealth>();

            // 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;
            }
        }
Ejemplo n.º 7
0
        private void OnTriggerEnter(Collider other)
        {
            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
            Collider[] colliders   = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);
            Collider[] collidersAI = Physics.OverlapSphere(transform.position, m_ExplosionRadius, LayerMask.GetMask("Bots"));
            Debug.Log(LayerMask.GetMask("Bots"));
            var collidersAux = new List <Collider>();

            collidersAux.AddRange(colliders);
            collidersAux.AddRange(collidersAI);
            Collider[] allColliders = collidersAux.ToArray();

            // Go through all the colliders...
            for (int i = 0; i < allColliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Calculate the amount of damage the target should take based on it's distance from the shell.
                float damage = CalculateDamage(targetRigidbody.position);

                // Deal this damage to the tank.
                targetHealth.TakeDamage(damage);
            }

            // Unparent the particles from the shell.
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system.
            m_ExplosionParticles.Play();

            // Play the explosion sound effect.
            m_ExplosionAudio.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
            Destroy(m_ExplosionParticles.gameObject, mainModule.duration);

            // Destroy the shell.
            Destroy(gameObject);
        }
Ejemplo n.º 8
0
    private void SendLocalPlayer()
    {
        Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>();
        var          health    = th.GetCurrentHealth();
        PlayInfoData playInfo  = new PlayInfoData(user.UserId, user.UserName, player.transform, false, (int)health, 15f);
        ProtocalData data      = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo);

        Send(data);
    }
Ejemplo n.º 9
0
    public void SendFire(float force)
    {
        Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>();
        var          health    = th.GetCurrentHealth();
        PlayInfoData playInfo  = new PlayInfoData(user.UserId, user.UserName, localTransform, true, (int)health, force);
        ProtocalData data      = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo);

        Send(data);
    }
Ejemplo n.º 10
0
        private void OnTriggerEnter(Collider other)
        {
            // HACK: Let's detonate an ink bomb jus before impact!
            Vector3 velocity = GetComponent <Rigidbody>().velocity;

            Splatter.instance.Splat(transform.position - velocity * Time.deltaTime * 1.0f, velocity);

            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Calculate the amount of damage the target should take based on it's distance from the shell.
                float damage = CalculateDamage(targetRigidbody.position);

                // Deal this damage to the tank.
                targetHealth.TakeDamage(damage);
            }

            // Unparent the particles from the shell.
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system.
            m_ExplosionParticles.Play();

            // Play the explosion sound effect.
            m_ExplosionAudio.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);

            // Destroy the shell.
            Destroy(gameObject);
        }
Ejemplo n.º 11
0
        void Awake()
        {
            tankMover = GetComponent<TankMovement>();
            tankNav = GetComponent<TankNavigation>();
            tankSensor = GetComponentInChildren<TankSensor>();
            tankShooter = GetComponent<TankShooting>();
            tankHealth = GetComponent<TankHealth>();

            Reset();
        }
Ejemplo n.º 12
0
 private void OnCollisionEnter(Collision coll)
 {
     Destroy(gameObject);
     if (coll.gameObject.name.Contains("CompleteBaja"))
     {
         Rigidbody  targetRigidbody = coll.gameObject.GetComponent <Rigidbody>();
         TankHealth targetHealth    = targetRigidbody.GetComponent <TankHealth>();
         targetHealth.TakeDamage(damage);
     }
 }
Ejemplo n.º 13
0
        float timer;                                // Timer for counting up to the next attack.


        void Awake()
        {
            // Setting up the references.
            player = GameObject.FindGameObjectWithTag("Player");
            if (player != null)
            {
                playerHealth = player.GetComponent <Complete.TankHealth> ();
            }
            enemyHealth = GetComponent <EnemyHealth>();
            anim        = GetComponent <Animator> ();
        }
Ejemplo 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();
        }
Ejemplo n.º 15
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();
        }
        private void OnTriggerEnter(Collider other)
        {
            // Recoge todos los colisionadores en una esfera desde la posición actual del proyectil hasta un radio del radio de explosión.
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Va a traves de todos los colisionadores
            for (int i = 0; i < colliders.Length; i++)
            {
                // Y se encuentra con su fisica.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // Si no tiene fisica, va al siguiente collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Añadimos una fuerza de explosion
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Encuentra TankHealth script asociado con el rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // Si no hay TankHealth script en el gameobject, va al siguiente collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Calcula la cantidad de daño que el objetivo debería recibir basado en su distancia con la bala.
                float damage = CalculateDamage(targetRigidbody.position);

                // Hace el daño al tanque
                targetHealth.TakeDamage(damage);
            }

            // Desaparecen las partículas del caparazón.
            m_ExplosionParticles.transform.parent = null;

            // Enciende las particulas
            m_ExplosionParticles.Play();

            // Enciende sonido de la explosion
            m_ExplosionAudio.Play();

            // cuando las particulas acaban, destruye el gameobject en el que estan.
            ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
            Destroy(m_ExplosionParticles.gameObject, mainModule.duration);

            // Destruye la bala
            Destroy(gameObject);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Przy kontakcie z trigerem tworze sferę dla pobrania wszystkich obiektów z pewnej maski
        /// Niszcy obiekt przy kontakcie
        /// </summary>
        /// <param name="other"></param>
        private void OnTriggerEnter(Collider other)
        {
            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // If they don't have a rigidbody, continue
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // If there is no TankHealth script attached to the gameobject, continue
                if (!targetHealth)
                {
                    continue;
                }

                // Calculate the amount of damage the target should take based on it's distance from the shell
                float damage = CalculateDamage(targetRigidbody.position);

                // Deal this damage to the tank
                targetHealth.TakeDamage(damage);
            }

            // Unparent the particles from the shell. idk why
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system
            m_ExplosionParticles.Play();

            // Play the explosion sound effect
            m_ExplosionAudio.Play();

            // When the particles have finished, destroy the shell
            ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
            Destroy(m_ExplosionParticles.gameObject, mainModule.duration);

            // Destroy the shell
            Destroy(gameObject);
        }
Ejemplo n.º 18
0
        private void OnTriggerEnter(Collider other)
        {
            // 以碰撞到的地方为中心,上面定义的半径球体内所有在tank层里的物体的collider集合
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // 遍历这些碰撞器组件
            for (int i = 0; i < colliders.Length; i++)
            {
                // 获取它身上的刚体组件
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // 如果没有刚体组件的话则跳过继续遍历
                if (!targetRigidbody)
                {
                    continue;
                }

                // 添加力,参数为(力的大小,力的中心位置,力的半径)
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // 获取Health组件
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // 如果没有的话则继续遍历下一个
                if (!targetHealth)
                {
                    continue;
                }

                // 根据距离爆炸位置的远近计算伤害值
                float damage = CalculateDamage(targetRigidbody.position);

                // 调用坦克身上的控制生命值的脚本来改变生命
                targetHealth.TakeDamage(damage);
            }

            // 脱离父子层级关系,避免级联销毁
            m_ExplosionParticles.transform.parent = null;

            // 播放粒子动画
            m_ExplosionParticles.Play();

            // 播放爆炸声音
            m_ExplosionAudio.Play();

            // 粒子动画播放完毕以后就销毁这个爆炸物体
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);

            // 销毁炮弹
            Destroy(gameObject);
        }
Ejemplo n.º 19
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();
        }
Ejemplo n.º 20
0
        private void OnCollisionEnter(Collision collision)
        {
            // Collect all the colliders in a sphere from the food's current position to a radius of the explosion radius.
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody.

                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.

                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!(targetHealth))
                {
                    continue;
                }

                // Deal this damage to the tank.
                targetHealth.TakeDamage(m_Damage);

                m_ExplosionParticles.transform.position = transform.position;
                m_ExplosionParticles.gameObject.SetActive(true);

                m_ExplosionParticles.Play();

                m_ExplosionAudio.Play();

                gameObject.SetActive(false);

                // Destroy the food.
                Destroy(gameObject);
            }
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Tank"))
     {
         gameObject.SetActive(false);
         Rigidbody  targetRigidbody = other.GetComponent <Rigidbody>();
         TankHealth tank            = targetRigidbody.GetComponent <TankHealth>();
         if (this.CompareTag("Canister"))
         {
             tank.Heal(healthAmount);
         }
         else if (this.CompareTag("Shield"))
         {
             tank.aktivateShield();
         }
         _spawn.ObjectPicked(this);
     }
 }
Ejemplo n.º 23
0
        private void OnTriggerEnter(Collider other)
        {
            // 从 炮弹的当前位置收集爆炸半径球体中的所有物理碰撞体
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);
            for (int i = 0; i < colliders.Length; i++)
            {
                // 找到刚体, 如果没有,下一个
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();
                if (!targetRigidbody)
                {
                    continue;
                }

                //爆炸对其添加推动力量,这是物理引擎上的操作
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius, 1.0f);

                // 找到与刚体关联的TankHealth脚本。如果没有,下一个
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();
                if (!targetHealth)
                {
                    continue;
                }
                Int32 receiverID = targetRigidbody.GetComponent <GameEntity>().id;
                // 计算伤害
                float damage = CalculateDamage(targetRigidbody.position);
                Debug.Log(" OnTriggerEnter  name = " + colliders[i].name + " i = " + i + " receiverID = " + receiverID + " damage = " + damage);
                Debug.Log(" ------- isPlayer ------" + isPlayer);
                if (isPlayer == true)
                {
                    KBEngine.Event.fireIn("takeDamage", receiverID, (Int32)damage);
                }
            }
            //从shell中取消颗粒特效。
            m_ExplosionParticles.transform.parent = null;

            // 播放爆炸的粒子特效,音频, 粒子特效每次只播一个,没播玩的算了。
            m_ExplosionParticles.Play();
            m_ExplosionAudio.Play();

            // 如果粒子特效播完了,销毁粒子特效所在的GameObject,然后消耗整个shell
            ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
            Destroy(m_ExplosionParticles.gameObject, mainModule.duration);
            Destroy(gameObject);
        }
Ejemplo n.º 24
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;
            }
        }
Ejemplo n.º 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()
        {
            // 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);
        }
Ejemplo n.º 26
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag.Equals("Canister") || other.tag.Equals("Shield"))
     {
     }
     else
     {
         // Find the TankHealth script associated with the rigidbody.
         Complete.TankHealth targetHealth = other.GetComponent <Complete.TankHealth>();
         // If there is no TankHealth script attached to the gameobject, go on to the next collider.
         if (!targetHealth)
         {
             Destroy(gameObject);
             return;
         }
         // Deal this damage to the tank.
         targetHealth.TakeDamage(damage);
         Destroy(gameObject);
     }
 }
        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>();
        }
Ejemplo n.º 28
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;
                                                                                                    }
                                                                                                }
Ejemplo n.º 29
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag.Equals("Tank") == true)
            {
                m_ObjectCollider.isTrigger = true;
                Debug.Log("Tank");
                // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
                Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

                // Go through all the colliders...
                for (int i = 0; i < colliders.Length; i++)
                {
                    // ... and find their rigidbody.
                    Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                    // If they don't have a rigidbody, go on to the next collider.
                    if (!targetRigidbody)
                    {
                        continue;
                    }

                    // Add an explosion force.
                    targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                    // Find the TankHealth script associated with the rigidbody.
                    TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                    // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                    if (!targetHealth)
                    {
                        continue;
                    }

                    // Calculate the amount of damage the target should take based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);

                    // Deal this damage to the tank.
                    targetHealth.TakeDamage(damage);
                }

                // Unparent the particles from the shell.
                m_ExplosionParticles.transform.parent = null;

                // Play the particle system.
                m_ExplosionParticles.Play();

                // Play the explosion sound effect.
                m_ExplosionAudio.Play();

                // Once the particles have finished, destroy the gameobject they are on.
                ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
                Destroy(m_ExplosionParticles.gameObject, mainModule.duration);

                // Destroy the shell.
                Destroy(gameObject);
            }
            else if (other.gameObject.tag.Equals("Wall") == true)
            {
                Debug.Log("Wall");
                //reflectedObject.position = Vector3.Reflect(originalObject.position, Vector3.right);
                m_ObjectCollider.isTrigger = false;
                StartCoroutine(wait());
            }
        }
Ejemplo n.º 30
0
        private void OnTriggerEnter(Collider other)
        {
            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Calculate the amount of damage the target should take based on it's distance from the shell.
                float damage = CalculateDamage(targetRigidbody.position);

                // Deal this damage to the tank.
                targetHealth.TakeDamage(damage);

                // add to damage report, so we can send to listensers
                // note that tank might damage itself, so we need to add all damages
                ITankAgent agent = targetRigidbody.GetComponent <ITankAgent>();
                if (agent == null)
                {
                    continue;
                }

                if (damageReport.ContainsKey(agent.GetPlayerNumber()))
                {
                    // if multiple parts of the tank are hit, we need to add up all the damage
                    damageReport[agent.GetPlayerNumber()] += damage;
                }
                else
                {
                    damageReport.Add(agent.GetPlayerNumber(), damage);
                }
            }

            // once all damages are calculated, send out damage report
            if (OnExplosion != null)
            {
                OnExplosion.Invoke(this, damageReport);
            }

            // Unparent the particles from the shell.
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system.
            m_ExplosionParticles.Play();

            // Play the explosion sound effect.
            // m_ExplosionAudio.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            ParticleSystem.MainModule mainModule = m_ExplosionParticles.main;
            Destroy(m_ExplosionParticles.gameObject, mainModule.duration);

            // Destroy the shell.
            Destroy(gameObject);
        }
Ejemplo n.º 31
0
        private void OnTriggerEnter(Collider other)
        {
            // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
            Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force with no vertical bias.
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                if (!targetHealth)
                {
                    continue;
                }

                // Create a vector from the shell to the target.
                Vector3 explosionToTarget = targetRigidbody.position - transform.position;

                // Calculate the distance from the shell to the target.
                float explosionDistance = explosionToTarget.magnitude;

                // Calculate the proportion of the maximum distance (the explosionRadius) the target is away.
                float relativeDistance = (m_ExplosionRadius - explosionDistance) / m_ExplosionRadius;

                // Calculate damage as this proportion of the maximum possible damage.
                float damage = relativeDistance * m_MaxDamage;

                // Make sure that the minimum damage is always 0.
                damage = Mathf.Max(0f, damage);

                // Deal this damage to the tank.
                targetHealth.Damage(damage);
            }

            // Unparent the particles from the shell.
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system.
            m_ExplosionParticles.Play();

            // Play the explosion sound effect.
            m_ExplosionAudio.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);

            // Destroy the shell.
            Destroy(gameObject);
        }
Ejemplo n.º 32
0
        public void OnTriggerEnter(Collider other)
        {
            if (aktiv == true)
            {
                exploded = true;
                //DestroyImmediate(gameObject);
                //transform.localScale = new Vector3(transform.localScale.x + 5, transform.localScale.y + 5, transform.localScale.z + 5);
                // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.

                Collider[] collidersTank = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);
                Collider[] collidersMine = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_MineMask);

                for (int i = 0; i < collidersMine.Length; i++)
                {
                    MineExplosion mine = collidersMine [i].GetComponent <MineExplosion> ();
                    if (mine.exploded != true)
                    {
                        mine.exploded = true;
                    }
                }

                // Go through all the colliders...
                for (int i = 0; i < collidersTank.Length; i++)
                {
                    // ... and find their rigidbody.
                    Rigidbody targetRigidbody = collidersTank [i].GetComponent <Rigidbody> ();

                    // If they don't have a rigidbody, go on to the next collider.
                    if (!targetRigidbody)
                    {
                        continue;
                    }

                    // Add an explosion force.
                    targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                    // Find the TankHealth script associated with the rigidbody.
                    TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth> ();

                    // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                    if (!targetHealth)
                    {
                        continue;
                    }

                    // Calculate the amount of damage the target should take based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);

                    // Deal this damage to the tank.
                    targetHealth.TakeDamage(damage);
                }

                // Unparent the particles from the shell.
                m_ExplosionParticles.transform.parent = null;

                // Play the particle system.
                m_ExplosionParticles.Play();

                // Play the explosion sound effect.
                m_ExplosionAudio.Play();

                // Once the particles have finished, destroy the gameobject they are on.
                Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration);

                // Destroy the mine.
                Destroy(gameObject);
            }
        }