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