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


C# Unit.IsAlive方法代码示例

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


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

示例1: Start

 public override RAIN.Action.Action.ActionResult Start(RAIN.Core.Agent agent, float deltaTime)
 {
     unitTarget = null;
     leader = agent.Avatar.GetComponent<Leader>();
     if(leader == null)
         return RAIN.Action.Action.ActionResult.FAILURE;
     Transform target = agent.actionContext.GetContextItem<Transform>("target");
     if(target == null)
         return RAIN.Action.Action.ActionResult.FAILURE;
     unitTarget = target.gameObject.GetComponent<Unit>();
     if(unitTarget == null || !unitTarget.IsAlive())
         return RAIN.Action.Action.ActionResult.FAILURE;
     return RAIN.Action.Action.ActionResult.SUCCESS;
 }
开发者ID:Jay2645,项目名称:ludum-dare-7dRTS,代码行数:14,代码来源:SquadAttackEnemy.cs

示例2: Start

 public override RAIN.Action.Action.ActionResult Start(RAIN.Core.Agent agent, float deltaTime)
 {
     hasEnemy = 0;
     bestUnit = null;
     enemy = agent.actionContext.GetContextItem<string>("enemy");
     if(enemy == "")
         return RAIN.Action.Action.ActionResult.FAILURE;
     if(us == null)
     {
         us = agent.actionContext.GetContextItem<Unit>("unit");
         if(us == null)
         {
             us = agent.Avatar.GetComponent<Unit>();
             if(us == null || !us.IsAlive())
                 return RAIN.Action.Action.ActionResult.FAILURE;
         }
     }
     if(!us.IsAlive())
         return RAIN.Action.Action.ActionResult.FAILURE;
     return RAIN.Action.Action.ActionResult.SUCCESS;
 }
开发者ID:Jay2645,项目名称:ludum-dare-7dRTS,代码行数:21,代码来源:DetectEnemy.cs

示例3: AddUnit

 public void AddUnit(Unit unit)
 {
     if (!IsAlive())
     {
         backloggedUnits.Add(unit);
         Invoke("AddAllUnits", timeToOurRespawn + 0.5f);
         return;
     }
     if (!unit.IsAlive())
     {
         backloggedUnits.Add(unit);
         Invoke("AddAllUnits", unit.GetTimeUntilRespawn() + 0.5f);
         return;
     }
     int id = unit.GetID();
     if (allUnits.ContainsKey(id))
     {
         allUnits[id] = unit;
     }
     else
     {
         allUnits.Add(id, unit);
     }
     if (friendlyFire || unit == this)
         return;
     Collider[] cols = unit.GetComponents<Collider>();
     foreach (Collider col in cols)
     {
         if (col.isTrigger || col.gameObject.GetComponent<Weapon>() != null)
             continue;
         col.enabled = true;
     }
     Unit[] allOurUnits = GetAllUnits();
     foreach (Unit u in allOurUnits)
     {
         if (u == unit || !u.IsAlive())
             continue;
         Physics.IgnoreCollision(u.collider, unit.collider, true);
     }
     Physics.IgnoreCollision(unit.collider, collider, true);
 }
开发者ID:Jay2645,项目名称:ludum-dare-7dRTS,代码行数:41,代码来源:Commander.cs

示例4: Shoot

 public bool Shoot(Unit enemy)
 {
     if (enemy == null || !enemy.IsAlive() || weapon == null || IsPlayer())
         return false;
     if (weapon.ammo <= 0)
         return false;
     float range = weapon.range;
     if (range < Vector3.Distance(enemy.transform.position, transform.position))
         return false;
     LookAt(enemy.transform.position);
     Vector3 weaponForward = weapon.transform.up;
     Ray shotRay = new Ray(weapon.transform.position, weaponForward);
     Debug.DrawRay(weapon.transform.position, weaponForward, Color.red);
     RaycastHit hitInfo;
     if (Physics.Raycast(shotRay, out hitInfo, range, raycastIgnoreLayers))
     {
         if (hitInfo.transform.tag == "Ground")
         {
             return false;
         }
         /*Unit unit = hitInfo.collider.gameObject.GetComponent<Unit>();
         if(unit != null)
         {
             return RAIN.Action.Action.ActionResult.FAILURE;
         }
         if(IsFriendly(unit))
         {
             Debug.Log (this+" is not shooting in case of friendly fire hitting "+unit);
             return RAIN.Action.Action.ActionResult.FAILURE;
         }*/
     }
     //else
     //return RAIN.Action.Action.ActionResult.FAILURE;
     if (status != UnitStatus.InCombat && status != UnitStatus.CapturingObjective)
     {
         SetStatus(UnitStatus.InCombat);
     }
     combatTime = 0.0f;
     weapon.Shoot();
     float accuracy = weapon.GetAccuracy();
     if (accuracy > 0.65f || movementType == MoveType.Strict)
     {
         return true;
     }
     else
     {
         MoveTo(enemy.gameObject, uName + "'s Attack Target", true, false, movementType, uName + " is moving to shoot at " + enemy, false);
         /*if(agent.MoveTo(enemy.transform.position,deltaTime))
         {
             return RAIN.Action.Action.ActionResult.SUCCESS;
         }*/
     }
     return true;
 }
开发者ID:Jay2645,项目名称:ludum-dare-7dRTS,代码行数:54,代码来源:Unit.cs


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