public void InitData(bool is_win)
 {
     if (is_win)
     {
         mTextResult.text = "Win!";
         AudioMananger.PlaySound("battle_success");
     }
     else
     {
         mTextResult.text = "False!";
         AudioMananger.PlaySound("battle_fail");
     }
 }
Example #2
0
    void Update()
    {
        if (mTarget == null) //如果敌人为空
        {
            if (mMoveSpeed > 0)
            {
                rang       = Vector3.Distance(transform.localPosition, mTargetPos); //子弹和敌人距离
                tutal_time = rang / mMoveSpeed;                                     //运行总时间
            }
            else
            {
                tutal_time = 0;
            }
            if (Time.deltaTime >= tutal_time) //如果每帧运行时间大于总时间
            {
                gameObject.SetActive(false);  //将子弹显示关闭
            }
            else
            {
                transform.localPosition = Vector3.Lerp(transform.localPosition, mTargetPos, Time.deltaTime / tutal_time);//从当前位置运行到敌人位置,时间:暂时不懂
            }
        }
        else//如果有敌人
        {
            mTargetPos = mTarget.transform.localPosition;
            if (mMoveSpeed > 0)
            {
                rang       = Vector3.Distance(transform.localPosition, mTargetPos);
                tutal_time = rang / mMoveSpeed;
            }
            else
            {
                tutal_time = 0;
            }

            if (Time.deltaTime >= tutal_time)   //如果每帧运行时间大于总时间,子弹到达敌人位置
            {
                AudioMananger.PlaySound("hit"); //播放击中音效
                mTarget.AddHP(-mAttack);        //敌人生命值减少
                gameObject.SetActive(false);    //将子弹隐藏
            }
            else
            {
                transform.localPosition = Vector3.Lerp(transform.localPosition, mTargetPos, Time.deltaTime / tutal_time);//同上
            }
        }
    }
Example #3
0
    public IEnumerator AttackButtle(Enemy enemy, Vector3 pos, float time)
    {
        AudioMananger.PlaySound("attack");
        yield return(new WaitForSeconds(time));

        Bullet bullet = BulletManager.CreatBullet(mBulletModelName);

        if (enemy != null)
        {
            bullet.InitData(enemy, BulletMoveSpd, mAttack);
        }
        else
        {
            bullet.InitData(pos, BulletMoveSpd, mAttack);
        }
        bullet.transform.localPosition = transform.localPosition;
    }