- 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); } } }
推薦閱讀
- 物聯網智慧安監技術
- 智能網聯汽車V2X與智能網聯設施I2X
- 計算機網絡安全實訓教程(第二版)
- Web Application Development with R Using Shiny
- HTML5 Game development with ImpactJS
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- NB-IoT物聯網技術解析與案例詳解
- Mastering TypeScript 3
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- 6G新技術 新網絡 新通信
- Master Apache JMeter:From Load Testing to DevOps
- 網管工具使用與技巧大全
- 網絡AI+:2030后的未來網絡
- 無線傳感器網絡定位技術
- TCP/IP基礎(第2版)