/// <summary>
    /// 帧事件绑定的方法
    /// </summary>
    public void Fire()
    {
        bullet = ObjectPool.Instance.GetObj(DBA.Instance.GetBulletNameByWeaponName(GetComponent <PlayerAttack>().currentWeaponName));
        Debug.Log("我是" + gameObject.name + ",我进行了攻击");


        BulletClassType bulletType = bullet.GetComponent <BulletClassType>();

        if (bulletType != null)
        {
            bulletType.ViewID = phv.ViewID;
        }
        Debug.Log(bullet);
        BulletCSharp bulletCsharp = bullet.GetComponent <BulletCSharp>();

        if (bulletCsharp != null)
        {
            bullet.transform.position = gameObject.transform.position;
            Destroy(bulletCsharp);
        }

        BulletCSharp bulletCSharp = bullet.AddComponent <BulletCSharp>();

        bulletCSharp.BAwake(gameObject.transform);
    }
Beispiel #2
0
    /// <summary>
    /// 获取新武器
    /// </summary>
    /// <param name="weaponName"></param>
    public void GetNewWeapon(string weaponName)
    {
        //GameObject gobj = ObjectPool.Instance.GetObj(weaponName);
        //网络实例化
        if (!phv.IsMine)
        {
            return;
        }
        gobj = PhotonNetwork.Instantiate(weaponName, transform.position, Quaternion.identity);

        gobj.GetComponent <WeaponAtrribute>().SetFather(GetComponent <PhotonView>().ViewID);
        //去掉克隆
        gobj.name = gobj.name.Replace("(Clone)", "");
        //获取子弹脚本
        BulletCSharp bulletCSharp = gobj.GetComponent <BulletCSharp>();

        //如果有子弹脚本,代表这是武器
        if (bulletCSharp != null)
        {
            //防止脱手
            gobj.GetComponent <Rigidbody>().isKinematic = true;
            //位置归零
            Destroy(bulletCSharp);
            //子弹初始化
            BulletInit(gobj, gameObject.transform);
        }
        //攻击等于数据库查找到的类型
        int attackType = DBA.Instance.GetWeaponTypeByName(weaponName);

        //武器类型等于查找到的攻击类型
        WeaponType = attackType;
        //当前武器等于生成的武器名字
        currentWeaponName = gobj.name;
        //如果没找到手就在找一遍
        if (handOfPlayers == null)
        {
            handOfPlayers = transform.GetComponentsInChildren <HandOfPlayer>();
        }

        for (int i = 0; i < handOfPlayers.Length; i++)
        {
            //有手就清除武器;
            handOfPlayers[i].ClearCurrentWeapon();
        }
        //如果类型1、2
        if (attackType == 1 || attackType == 2)
        {
            for (int i = 0; i < handOfPlayers.Length; i++)
            {
                if (handOfPlayers[i].handType == HandType.Right)
                {
                    handOfPlayers[i].ChangeCurrentWeapon(gobj);
                }
            }
        }
        //类型3、4
        if (attackType == 3 || attackType == 4)
        {
            for (int i = 0; i < handOfPlayers.Length; i++)
            {
                if (handOfPlayers[i].handType == HandType.Left)
                {
                    handOfPlayers[i].ChangeCurrentWeapon(gobj);
                }
            }
        }
        //武器动画
        ChangeAttackAnimator(currentWeaponName);
    }