- Unity Artificial Intelligence Programming
- Dr. Davide Aversa Aung Sithu Kyaw Clifford Peters
- 88字
- 2021-06-10 18:57:49
Shooting bullet
Whenever the player clicks the left mouse button, we check whether the total elapsed time since the last fire has passed the fire rate of the weapon. If it has, then we create a new Bullet object at the SpawnPoint variable's position. In this way, we can prevent the player from shooting a continuous stream of bullets:
void UpdateWeapon() { if (Input.GetMouseButtonDown(0)) { elapsedTime += Time.deltaTime; if (elapsedTime >= shootRate) { //Reset the time elapsedTime = 0.0f; //Instantiate the bullet Instantiate(Bullet, bulletSpawnPoint.position, bulletSpawnPoint.rotation); } } }
推薦閱讀
- 智慧城市:大數據、互聯網時代的城市治理(第4版)
- 連接未來:從古登堡到谷歌的網絡革命
- C++黑客編程揭秘與防范
- Hands-On Chatbots and Conversational UI Development
- Web Application Development with R Using Shiny
- 信息通信網絡建設安全管理概要2
- React:Cross-Platform Application Development with React Native
- 網絡基礎與網絡管理項目化教程
- OMNeT++與網絡仿真
- Building Web Applications with ArcGIS
- 計算機網絡技術
- 小型局域網組建
- 人際網絡
- 區塊鏈技術與應用:打造分布式商業新生態
- 新IP:面向泛在全場景的未來數據網絡