Ejemplo n.º 1
0
 void Update()
 {
     if (!attackTask.IsAttacking)
     {
         if (gameObject.layer == 8)//player layer
         {
             for (int i = 0; i < Unit.EnemyUnits.Count; i++)
             {
                 if (StartAttackRange > Vector3.Distance(Unit.EnemyUnits[i].transform.position, transform.position))
                 {
                     attackTask.StartTask(Unit.EnemyUnits[i].transform);
                     break;
                 }
             }
         }
         else if (gameObject.layer == 9)//enemy layer
         {
             for (int i = 0; i < Unit.PlayerUnits.Count; i++)
             {
                 if (StartAttackRange > Vector3.Distance(Unit.PlayerUnits[i].transform.position, transform.position))
                 {
                     attackTask.StartTask(Unit.PlayerUnits[i].transform);
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    private void OnRightClick()
    {
        GameObject hittedObj      = GameObjectUnderMouse();
        int        hittedObjLayer = hittedObj.layer;

        if (hittedObjLayer == layerMaskToLayer(TerrainLayerMask))
        {
            ClearDeadUnits();
            SortByDistance(endDragRayHit.point);
            for (int i = 0; i < SelectedUnits.Count; i++)
            {
                if (SelectedUnits[i].IsTaskAvailable <GoToTask>())
                {
                    GoToTask goToTask = SelectedUnits[i].ChangeTask <GoToTask>();
                    goToTask.StartTask(endDragRayHit.point);
                }
            }
        }
        else if (hittedObjLayer == layerMaskToLayer(EnemyUnitsLayerMask) || hittedObjLayer == layerMaskToLayer(EnemyBuildingLayerMask))
        {
            ClearDeadUnits();
            SortByDistance(hittedObj.transform.position);
            for (int i = 0; i < SelectedUnits.Count; i++)
            {
                if (SelectedUnits[i].IsTaskAvailable <AttackTask>())
                {
                    AttackTask attackTask = SelectedUnits[i].ChangeTask <AttackTask>();
                    attackTask.StartTask(hittedObj.transform);
                }
            }
        }
    }