当前位置: 首页>>代码示例>>C#>>正文


C# Unit.drawAttack方法代码示例

本文整理汇总了C#中Unit.drawAttack方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.drawAttack方法的具体用法?C# Unit.drawAttack怎么用?C# Unit.drawAttack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unit的用法示例。


在下文中一共展示了Unit.drawAttack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

 // Update is called once per frame
 public virtual void Update(Unit unit)
 {
     //If unit has arrived at destination then stop it
     float distance = Vector3.Distance(unit.getDestination(), unit.transform.position);
     if (distance < stoppingDistance) {
         unit.GetComponent<NavMeshAgent>().destination = unit.transform.position;
         unit.setDestination (unit.transform.position);
         unit.changeState (new Idle());
     }
     if (unit.GetComponent<NavMeshAgent>().nextPosition == unit.getDestination ()) {
         unit.GetComponent<NavMeshAgent>().updatePosition = false;
     }
     /* COMBAT (DRIVEBY STYLE) */
     foreach (Collider enemy in Physics.OverlapSphere (unit.transform.position, unit.getRange(),1<<10)){
         Unit enemyUnit = enemy.GetComponent<Unit>();
         if (enemyUnit != null && unit.team != enemyUnit.team){ // cant we all just get along?
             unit.lookAtPos(enemyUnit.transform.position);
             if(unit.canFire ()){
                 enemyUnit.GetComponent<Health>().applyDamage(unit.getDamage());
                 unit.resetCooldown ();
                 unit.drawAttack(unit,enemyUnit, unit.renderer.material.color);
             }
             break;
         }
     }
 }
开发者ID:schabou,项目名称:MobileRTS,代码行数:27,代码来源:Moving.cs

示例2: Update

 // Update is called once per frame
 public virtual void Update(Unit unit)
 {
     // if target has died
     if (unit.getTarget() == null || unit.getTarget().GetComponent<Health>().currentHealth <= 0){
         unit.setTarget(null);
         unit.setDestination(Vector3.zero);
         unit.GetComponent<NavMeshAgent>().updatePosition = false;
         unit.changeState (new Idle());
         return;
     }
     // else, if enemy still alive
     Unit lastEnemy = null;
     bool inRange = false;
     foreach (Collider enemy in Physics.OverlapSphere (unit.transform.position, unit.getRange(),1<<10)){
         Unit enemyUnit = enemy.GetComponent<Unit>();
         if (enemyUnit != null && unit.team != enemyUnit.team){
             lastEnemy = enemyUnit;
             if (enemyUnit == unit.getTarget()){
                 inRange = true;
                 unit.setDestination (Vector3.zero);
                 unit.GetComponent<NavMeshAgent>().updatePosition = false;
                 // attack target unit
                 unit.lookAtPos(enemyUnit.transform.position);
                 if(unit.canFire ()){
                     enemyUnit.GetComponent<Health>().applyDamage(unit.getDamage());
                     unit.resetCooldown ();
                     unit.drawAttack(unit,enemyUnit, unit.renderer.material.color);
                 }
                 break;
             }
         }
     }
     if (!inRange){
         // for now, it finds a path every update. this will be fixed in future
         unit.GetComponent<NavMeshAgent>().destination = unit.getTarget ().transform.position;
         unit.setDestination(unit.getTarget ().transform.position);
         unit.GetComponent<NavMeshAgent>().updatePosition = true;
         if (lastEnemy != null){ // not in range of target, but in range of another enemy
             unit.lookAtPos(lastEnemy.transform.position);
             if(unit.canFire ()){
                 lastEnemy.GetComponent<Health>().applyDamage(unit.getDamage());
                 unit.resetCooldown ();
                 unit.drawAttack(unit,lastEnemy, unit.renderer.material.color);
             }
         }
     }
 }
开发者ID:schabou,项目名称:MobileRTS,代码行数:48,代码来源:Attacking.cs

示例3: Update

 // Update is called once per frame
 public virtual void Update(Unit unit)
 {
     /* COMBAT (HOLD POSITION STYLE) */
     foreach (Collider enemy in Physics.OverlapSphere (unit.transform.position, unit.getRange(),1<<10)){
         Unit enemyUnit = enemy.GetComponent<Unit>();
         if (enemyUnit != null && unit.team != enemyUnit.team){ // cant we all just get along?
             unit.lookAtPos(enemyUnit.transform.position);
             if(unit.canFire ()){
                 enemyUnit.GetComponent<Health>().applyDamage(unit.getDamage());
                 unit.resetCooldown ();
                 unit.drawAttack(unit,enemyUnit, unit.renderer.material.color);
             }
             break;
         }
     }
 }
开发者ID:schabou,项目名称:MobileRTS,代码行数:17,代码来源:Idle.cs


注:本文中的Unit.drawAttack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。