- Unity Artificial Intelligence Programming
- Dr. Davide Aversa Aung Sithu Kyaw Clifford Peters
- 186字
- 2021-06-10 18:57:48
Initialization
In the following code, we can see our TankController class. First, we set up our Start function and the Update functions.
The code in the PlayerTankController.cs file is as follows:
using UnityEngine; using System.Collections; public class PlayerTankController : MonoBehaviour { public GameObject Bullet; private Transform Turret; private Transform bulletSpawnPoint; private float curSpeed, targetSpeed, rotSpeed; private float turretRotSpeed = 10.0f; private float maxForwardSpeed = 300.0f; private float maxBackwardSpeed = -300.0f; //Bullet shooting rate protected float shootRate = 0.5f; protected float elapsedTime; void Start() { //Tank Settings rotSpeed = 150.0f; //Get the turret of the tank Turret = gameObject.transform.GetChild(0).transform; bulletSpawnPoint = Turret.GetChild(0).transform; } void Update() { UpdateWeapon(); UpdateControl(); }
The first—and only—child object of our tank entity is the Turret object, and the first—and only—child of the Turret object is the bulletSpawnPoint. The Start function finds these objects and then assigns them to their respective variables. Later, after we create the Bullet object, we assign it from the inspector. Also, we included the Update function that calls our UpdateControl and UpdateWeapon functions, which we will create soon.
推薦閱讀
- 面向物聯網的CC2530與傳感器應用開發
- 物聯網短距離無線通信技術應用與開發
- 5G承載網網絡規劃與組網設計
- 物聯網檢驗檢測技術
- 農產品物聯網研究與應用
- Spring Cloud微服務架構進階
- 端到端QoS網絡設計
- Learning Windows 8 Game Development
- Microsoft Power Platform Enterprise Architecture
- 5G時代的大數據技術架構和關鍵技術詳解
- 物聯網的機遇與利用
- 華為HCIA-Datacom認證指南
- 信息技術安全評估準則:源流、方法與實踐
- React Design Patterns and Best Practices(Second Edition)
- 想象的互動:網絡人際傳播中的印象形成