Exemplo n.º 1
0
    public void TakeDamage(GameObject killer, int enemydamage)
    {
        //Debug.Log(gameObject.name + " take damage from " + killer.gameObject.name);
        if (state != State.dead)
        {
            if (priority != 1 && priority != 3)
            {
                state = State.attack;
                anim.SetBool("Run", true);
                anim.SetBool("Attack", true);
            }
            if (enemy != killer)
            {
                enemy = killer;
            }
            if (friend == killer)
            {
                friend = null;
                clan.DeleteFromClan(gameObject);
                clan = null;
            }
            // Debug.Log("hp before " + hp);
            hp -= Random.Range(enemydamage, enemydamage + 10);
            //  Debug.Log("hp after " + hp);
            if (hp <= 0)
            {
                //Debug.Log(gameObject.name + " is dead");
                nav.ResetPath();
                nav.enabled = false;
                enemy       = null;
                if (clan != null)
                {
                    Debug.Log("удаляем умершего");
                    clan.DeleteFromClan(gameObject);
                    clan = null;
                }
                if (priority == 6)
                {
                    Creator.ChangeInClans();
                }
                state = State.dead;


                anim.SetTrigger("Death");
                priority = 3;
                CreatorRef.SomebodyDead(gameObject);
                StopAllCoroutines();
            }
        }
    }
Exemplo n.º 2
0
    public void TakeDamage(GameObject killer, int enemydamage)
    {
        if (currenttask.action != Action.Dead)                        //если не мертвый
        {
            if (priority != 1 && currenttask.action != Action.Attack) //не заяц
            {
                Tasks.Push(currenttask);
                if (killer.tag == "Player")
                {
                    currenttask = new Task(Action.RunFor, killer, killer.GetComponent <PlayerMove>().priority);
                    runuptask();
                    reactiononplayer = 2;
                }
                else
                {
                    currenttask = new Task(Action.RunFor, killer, killer.GetComponent <CleverAI>().priority);
                    runuptask();
                }
            }
            hp -= Random.Range(enemydamage, enemydamage + 10);
            if (clan != null)
            {
                if (killer == clan.Leader)
                {
                    clan.DeleteFromClan(gameObject);
                    clan = null;
                    Creator.ChangeInClans();
                }
            }
            if (hp <= 0)
            {
                AddTask(new Task(Action.Dead, null, 0));
                priority = 3;
                CreatorRef.SomebodyDead(gameObject);

                if (clan != null)
                {
                    clan.DeleteFromClan(gameObject);
                    clan = null;
                    Creator.ChangeInClans();
                }
            }
        }
    }