Example #1
0
    /// <summary>
    /// 开火
    /// </summary>
    ///
    public void Firing(Vector3 direction)//玩家 枪 发射 :枪口方向, 敌人发射 :从枪口位置朝向玩家头部位置
    {
        //如果敌人枪没有动画 不调用准备子弹方法 准备子弹失败
        if (anim != null && Ready() == false)
        {
            audioSource.PlayOneShot(clipDryFire);
            return;
        }


        //判断弹夹内是否包含子弹



        //播放音频
        audioSource.PlayOneShot(clipFire);
        //如果具有动画,播放动画
        if (anim)
        {
            anim.action.PlayQueued(anim.fireAnimName);
        }

        //开启火光
        if (muzzleFlash)
        {
            muzzleFlash.DisplayFlash();
        }
        //创建子弹
        GameObject bulletGo = Instantiate(bulletPrefab, firePoint.transform.position, Quaternion.LookRotation(direction));

        //传递信息
        bulletGo.GetComponent <Bullet>().atk = atk;
    }
Example #2
0
    //发射子弹
    //玩家枪发射的子弹,朝向枪口正方向
    //敌人发射的子弹,朝向玩家
    public bool Firing(Vector3 dir)
    {
        //判定能否发射子弹(弹匣子弹数     攻击动画是否播放)
        if (!Ready())
        {
            return(false);
        }

        //如果可以发射子弹
        //1.创建子弹(创建谁?在哪?旋转?)
        GameObject bulletGO = Instantiate(bulletPrefab, firePoint.position, Quaternion.LookRotation(dir)) as GameObject;

        //初始化,传递攻击力、攻击距离
        bulletGO.GetComponent <Bullet>().Init(atk, atkDistance);

        //2.播放声音
        source.Play();
        //3.播放动画
        //anim.Play(anim.fireAnimName); 因为录制的动画片段很短,所以使用PlayQueued播放
        anim.PlayQueued(anim.fireAnimName);

        //4.显示火花
        flash.DisplayFlash();

        return(true);
    }