// Update is called once per frame
 public override void Update()
 {
     // 若坦克处于非活跃或游戏结束,则销毁动作
     if (!gameobject.activeSelf || firstController.GetGameState() == GameState.GAMEOVER)
     {
         this.destroy   = true;
         agent.velocity = Vector3.zero;
         agent.ResetPath();
         return;
     }
     // 若坦克处于非跟踪玩家状态,则销毁动作
     if (!gameobject.GetComponent <TankData>().follow)
     {
         this.destroy   = true;
         agent.velocity = Vector3.zero;
         agent.ResetPath();
         this.callback.SSActionEvent(this, 1, gameobject);
         return;
     }
     // 跟踪玩家
     agent.SetDestination(player.transform.position);
     // 每隔两秒发一次子弹
     shootTime -= Time.deltaTime;
     if (shootTime <= 0)
     {
         shootTime = 2f;
         shoot();
     }
 }
示例#2
0
 // Update is called once per frame
 public override void Update()
 {
     // 若坦克处于非活跃或游戏结束,则销毁动作
     if (!gameobject.activeSelf || firstController.GetGameState() == GameState.GAMEOVER)
     {
         this.destroy   = true;
         agent.velocity = Vector3.zero;
         agent.ResetPath();
         return;
     }
     // 若坦克处于跟踪玩家状态,则销毁动作
     if (gameobject.GetComponent <TankData>().follow)
     {
         this.destroy   = true;
         agent.velocity = Vector3.zero;
         agent.ResetPath();
         this.callback.SSActionEvent(this, 0, gameobject);
         return;
     }
     // 在地图上随机一个坐标进行追踪,若距离目标小于10,则更换追踪目标,实现随机巡逻
     while (Vector3.Distance(gameobject.GetComponent <TankData>().target, transform.position) < 10)
     {
         gameobject.GetComponent <TankData>().target = new Vector3(Random.Range(-50, 50), 0, Random.Range(-50, 50));
     }
     agent.SetDestination(gameobject.GetComponent <TankData>().target);
 }