Example #1
0
    public void TakeDamage(int attack)
    {
        if (state1 == storemanstate1.Death)
        {
            return;
        }
        float value = Random.Range(0f, 1f);

        if (value < miss_rate1)//Miss效果
        {
            //AudioSource.PlayClipAtPoint(miss_sound, transform.position);
        }
        else
        {
            this.hp -= attack;
            Slider_c7.instance.SetValue(hp);
            GameObject.Find("Canvas").GetComponent <HudText>().HUD(attack);

            StartCoroutine(ShowBodyRed1());
            if (hp <= 0)
            {
                state1 = storemanstate1.Death;
            }
        }
    }
Example #2
0
    // Start is called before the first frame update
    void Start()
    {
        state1              = storemanstate1.Idle;                        //初始化初始状态
        hp                  = 1000;
        animall_now1        = animall_idle1;                              //初始化初始动画
        aniname_attack_now1 = aniname_normal1attack1_1;                   //初始化攻击动画
        cc1                 = this.GetComponent <CharacterController>();
        player1             = GameObject.FindGameObjectWithTag("Player"); //获取玩家对象
        target1             = player1.transform;                          //获取玩家的位置
        animation1          = GetComponent <Animation>();

        addAnimationEvent(aniname_normal1attack1_1, "controlhp");
        addAnimationEvent(aniname_normal1attack2_1, "controlHP2");
        addAnimationEvent(aniname_normal1attack3_1, "controlHP3");
        addAnimationEvent(aniname_normal1attack4_1, "controlHP4");
        addAnimationEvent(aniname_crazyattack_1, "controlHP5");
        c = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterAttackSystem>();
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        float distance = Vector3.Distance(target1.position, transform.position); //计算玩家与野怪的距离

        if (distance <= maxDistance1)                                            //判断玩家是否在野怪的攻击范围内
        {
            state1 = storemanstate1.Attack;
        }
        if (distance <= minDistance1)
        {
            //始终朝向玩家
            transform.LookAt(target1);
        }
        if (state1 == storemanstate1.Attack)
        {
            AutoAttack1();                       //野怪执行攻击
        }
        else if (state1 == storemanstate1.Death) //如果野怪的状态是死亡,则播放死亡动画
        {
            animation1.CrossFade(animall_death1);
        }
        else//野怪处于其他状态
        {
            animation1.CrossFade(animall_now1);//播放野怪当前动画
            if (animall_now1 == animall_walk1)
            {
                cc1.SimpleMove(transform.forward * speed1);
            }
            time1r1 += Time.deltaTime;//计时器
            if (time1r1 >= time1)
            {
                time1r1 = 0;
                Randomstate1();//随机产生行走和静立状态
            }
        }
        if (hp <= 0)
        {
            state1 = storemanstate1.Death;
            animation1.CrossFade(animall_death1);
            Destroy(this.gameObject, 1.5f);
        }
    }