Tanks Unity Tutorial
来源:互联网 发布:gsm是什么网络制式 编辑:程序博客网 时间:2024/06/03 20:06
YouTube地址:https://www.youtube.com/watch?v=_In3KT97aTw
实现射击的效果:
using UnityEngine;using UnityEngine.UI;public class TankShooting : MonoBehaviour{ public int m_PlayerNumber = 1; public Rigidbody m_Shell; public Transform m_FireTransform; public Slider m_AimSlider; public AudioSource m_ShootingAudio; public AudioClip m_ChargingClip; public AudioClip m_FireClip; public float m_MinLaunchForce = 15f; public float m_MaxLaunchForce = 30f; public float m_MaxChargeTime = 0.75f; private string m_FireButton; private float m_CurrentLaunchForce; private float m_ChargeSpeed; private bool m_Fired; private void OnEnable() { m_CurrentLaunchForce = m_MinLaunchForce; m_AimSlider.value = m_MinLaunchForce; } private void Start() { m_FireButton = "Fire" + m_PlayerNumber; m_ChargeSpeed = (m_MaxLaunchForce - m_MinLaunchForce) / m_MaxChargeTime; } private void Update() { // Track the current state of the fire button and make decisions based on the current launch force. m_AimSlider.value = m_CurrentLaunchForce; if (m_CurrentLaunchForce >= m_MaxLaunchForce && !m_Fired) { m_CurrentLaunchForce = m_MaxLaunchForce; Fire (); } else if (Input.GetButtonDown (m_FireButton)) { m_Fired = false; m_CurrentLaunchForce = m_MinLaunchForce; m_ShootingAudio.clip = m_ChargingClip; m_ShootingAudio.Play (); } else if (Input.GetButton (m_FireButton) && !m_Fired) { m_CurrentLaunchForce += m_ChargeSpeed * Time.deltaTime; m_AimSlider.value = m_CurrentLaunchForce; } else if (Input.GetButtonUp (m_FireButton)&& !m_Fired) { Fire (); } } 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; // 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; }}
0 0
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks!Tutorial初学者可能会出现的问题
- Unity学习之Tanks官网教程
- Unity 3D官方教程——Tanks!学习记录
- unity NGUI Tutorial Tools
- unity官方教程Tanks《坦克大战》中摄像机size的调整的疑问
- Unity iPhone Touch Animation Tutorial
- unity NUGUI tutorial the basics
- unity NGUI Tutorial context menus
- unity NGUI Tutorial event system
- unity NGUI tutorial more events
- 波动率曲面示例
- dts中的xxxx-cells
- leetcode31Next Permutation
- supervisor运行golang守护进程
- Storm之Toplogy编程
- Tanks Unity Tutorial
- HBase优化之bulkload写入
- VS2010 警告1warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s
- A星算法解决TSP问题
- 七种Mysql表类型
- ARM的字对齐问题总结
- 基于Java的webservice创建与soap方式调用
- android系统架构详解
- 微服务,微架构[二]之springboot集成jdbc