Пример #1
0
    // Update is called once per frame
    void Update()
    {
        displacement.x = chara.transform.position.x - transform.position.x;
        displacement.z = chara.transform.position.z - transform.position.z;

        if ((displacement.magnitude < attackDistance) || isAttacking)
        {
            if (!isAttacking)
            {
                hitCheckTimer      = 0.3f;
                isAttacking        = true;
                animation.wrapMode = WrapMode.Once;
                animation.Play("Attack");
                bms.disable();
            }

            hitCheckTimer -= Time.deltaTime;

            if (hitCheckTimer <= 0f)
            {
                if (Physics.Raycast(transform.position, displacement, out colCast, attackDistance))
                {
                    if (colCast.transform.gameObject == chara)
                    {
                        charaStats.health -= stats.damage;
                        hitCheckTimer      = 99999f;
                    }
                }
            }

            if (!animation.IsPlaying("Attack"))
            {
                isAttacking = false;
            }
        }
        else
        {
            bms.enable();
        }

        if (stats.health <= 0)
        {
            Destroy(gameObject);
        }
    }
Пример #2
0
    void Update()
    {
        if (!stats.initialized)
        {
            initStats();
        }
        if (stats.health <= 0)
        {
            Destroy(gameObject);
        }

        //Compute vector to character.
        toChar = chara.transform.position - transform.position;

        if (state == 0)
        {
            if (toChar.magnitude < range)
            {
                bms.disable();
                float spellRoll = Random.Range(0f, 1f);
                if (spellRoll < 0.2f)
                {
                    state = 1;
                }
                else
                {
                    state = 2;
                }
            }
        }
        else if (state == 1)
        {
            if (!isAttacking)
            {
                isAttacking        = true;
                animation.wrapMode = WrapMode.Loop;
                animation.Play("Attack1");
                timer = castTime;
                (Instantiate(Resources.Load("inferno")) as GameObject).transform.position = new Vector3(chara.transform.position.x, 0.1f, chara.transform.position.z);
            }
            else
            {
                timer -= Time.deltaTime;
                if (timer <= 0f)
                {
                    isAttacking = false;
                    state       = 0;
                    bms.enable();
                }
            }
        }
        else if (state == 2)
        {
            if (!isAttacking)
            {
                (Instantiate(Resources.Load("FireBall")) as GameObject).transform.position = transform.position;
                isAttacking = true;
                bms.disable();
                animation.wrapMode = WrapMode.Once;
                animation.Play("Attack2");
            }
            else
            {
                if (!animation.IsPlaying("Attack2"))
                {
                    isAttacking = false;
                    state       = 0;
                    bms.enable();
                }
            }
        }
    }