- 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); } } }
推薦閱讀
- Web安全防護指南:基礎篇
- Aptana Studio Beginner's Guide
- 智能網聯汽車V2X與智能網聯設施I2X
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 網絡安全技術與解決方案(修訂版)
- 計算機網絡工程實用教程(第2版)
- Learning Swift(Second Edition)
- WordPress Web Application Development
- SAE原理與網絡規劃
- Learning Storm
- Microsoft Power Platform Enterprise Architecture
- AWS Lambda Quick Start Guide
- Hands-On Docker for Microservices with Python
- Enterprise ApplicationDevelopment with Ext JSand Spring
- 新IP:面向泛在全場景的未來數據網絡