예제 #1
0
        private void Fire()
        {
            Vector3 opponent_position = transform.InverseTransformPoint(tankAgent.opponent.transform.position);

            tankAgent.AddReward(-Mathf.Abs(opponent_position.x));

            // Set the fired flag so only Fire is only called once.
            m_Fired = true;

            // Create an instance of the shell and store a reference to it's rigidbody.
            Rigidbody shellInstance =
                Instantiate(m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;

            ShellExplosion shellExplosion = shellInstance.GetComponent <ShellExplosion>();

            shellExplosion.owner  = gameObject;
            shellExplosion.target = tankAgent.opponent;

            // Set the shell's velocity to the launch force in the fire position's forward direction.
            shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;

            // Change the clip to the firing clip and play it.
            m_ShootingAudio.clip = m_FireClip;
            m_ShootingAudio.Play();

            // Reset the launch force.  This is a precaution in case of missing button events.
            m_CurrentLaunchForce = m_MinLaunchForce;
        }
예제 #2
0
        private void Fire()
        {
            //// Set the fired flag so only Fire is only called once.
            //m_Fired = true;

            GameObject     shellInstance = ShellPool.Create(m_Shell, m_FireTransform.transform.position, m_FireTransform.transform.rotation) as GameObject;
            ShellExplosion shell         = shellInstance.GetComponent <ShellExplosion>();

            shell.Reset();
            shell.m_PhyWorld     = m_PhyWorld;
            shell.m_PlayerNumber = m_PlayerNumber;

            //// Create an instance of the shell and store a reference to it's rigidbody.
            //Rigidbody shellInstance =
            //    Instantiate (m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;

            //// Set the shell's velocity to the launch force in the fire position's forward direction.
            //shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;

            //// Change the clip to the firing clip and play it.
            //m_ShootingAudio.clip = m_FireClip;
            //m_ShootingAudio.Play ();

            //// Reset the launch force.  This is a precaution in case of missing button events.
            //m_CurrentLaunchForce = m_MinLaunchForce;
        }
예제 #3
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);
        }
예제 #4
0
        private void Fire()
        {
            // Set the fired flag so only Fire is only called once.
            m_Fired = true;

            // Create an instance of the shell and store a reference to it's rigidbody.
            Rigidbody shellInstance =
                Instantiate(m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;
            ShellExplosion shellExplosion = shellInstance.gameObject.GetComponent <ShellExplosion>();

            shellExplosion.playerNumber       = m_PlayerNumber;
            shellExplosion.m_DamageMultiplier = m_DamageMultiplier;

            // Set the shell's velocity to the launch force in the fire position's forward direction.
            shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward * 4f;

            // Change the clip to the firing clip and play it.
            m_ShootingAudio.clip = m_FireClip;
            m_ShootingAudio.Play();

            // Reset the launch force.  This is a precaution in case of missing button events.
            m_CurrentLaunchForce = m_MinLaunchForce;
        }