Beispiel #1
0
 void SeekState()
 {
     CharacterCommands.GetVision(chara, detectable);
     if (chara.FoundItems.Count > 0)
     {
         foreach (Transform item in chara.FoundItems)
         {
             if (item.tag == "Weapon" && item.GetComponent <Weapon>().Damage > chara.Weapon.Damage)
             {
                 target = item;
                 break;
             }
             else if (item.tag == "Treasure")
             {
                 target = item;
                 break;
             }
         }
         if (!target && !chara.FullFoodBag)
         {
             List <Transform> foundFood = new List <Transform>();
             foreach (Transform item in chara.FoundItems)
             {
                 if (item.tag == "Food")
                 {
                     foundFood.Add(item);
                 }
             }
             target = GetClosest(foundFood);
         }
         if (!enemy)
         {
             List <Transform> enemyList = new List <Transform>();
             foreach (Transform _enemy in chara.FoundItems)
             {
                 if (_enemy.tag == "Player" && _enemy.GetComponent <CharacterBehaviours>() != chara)
                 {
                     enemyList.Add(_enemy);
                     print(_enemy.name);
                 }
             }
             if (enemyList.Count > 1)
             {
                 GameObject closestEnemy = GetClosest(enemyList).gameObject;
                 enemy = closestEnemy.GetComponent <CharacterBehaviours>();
             }
             else if (enemyList.Count != 0)
             {
                 enemy = enemyList[0].GetComponent <CharacterBehaviours>();
             }
         }
     }
 }
Beispiel #2
0
 // Update is called once per frame
 void Update()
 {
     if (chara.IsDead)
     {
         return;
     }
     if (!target)
     {
         CharacterCommands.GetVision(chara, players);
     }
     else
     {
         if (Vector2.Distance(transform.position, target.transform.position) <= chara.Weapon.Range)
         {
             CharacterCommands.Attack(chara, target);
         }
     }
 }