Beispiel #1
0
    //回收投掷武器
    public void FreeWeapon(WeaponData weapon)
    {
        List <WeaponData> usingWeapon;
        List <WeaponData> unusedWeapon;

        //获取类型
        int type = weapon.type;

        //检查词典链表是否为空,并进行初始化
        if (usingWeapon_.ContainsKey(type) == false)
        {
            usingWeapon_.Add(type, new List <WeaponData>());
        }
        if (unusedWeapon_.ContainsKey(type) == false)
        {
            unusedWeapon_.Add(type, new List <WeaponData>());
        }

        //获取对相应武器类型的链表引用
        usingWeapon  = usingWeapon_[type];
        unusedWeapon = unusedWeapon_[type];

        //将投掷武器设置为smart terrain surface的子对象
        weapon.transform.SetParent(sceneController.gameObject.transform);

        //将相应飞镖置为不可用
        weapon.gameObject.SetActive(false);
        //恢复飞镖出场设置
        switch (type)
        {
        case 1:
            weapon.gameObject.transform.position    = weapon.transform.position;
            weapon.gameObject.transform.eulerAngles = weapon.transform.eulerAngles;
            break;

        case 2:
            weapon.gameObject.transform.position    = monsterWeapon.transform.position;
            weapon.gameObject.transform.eulerAngles = monsterWeapon.transform.eulerAngles;
            break;
        }
        //初速度置为0
        weapon.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        weapon.GetComponent <Rigidbody>().velocity        = Vector3.zero;
        //移出使用链表
        usingWeapon.Remove(weapon);
        //加入回收链表
        unusedWeapon.Add(weapon);
    }
Beispiel #2
0
    public void SetNewWeapon(WeaponData newWeapon)
    {
        //1 удаляем предыдущее

        if (CurrentWeapon != null)
        {
            CurrentWeapon.GetComponent <Collider2D>().enabled = true;
            Debug.Log(CurrentWeapon.name + "    " + newWeapon.name);
            CurrentWeapon.transform.parent = null;
            // Destroy(CurrentWeapon.gameObject);
        }
        CurrentWeapon = newWeapon;
        Vector3 scale = newWeapon.transform.localScale;

        newWeapon.transform.SetParent(transform);
        newWeapon.GetComponent <Collider2D>().enabled = false;
        newWeapon.transform.localPosition             = newWeapon.LocalPosition;
        newWeapon.transform.localScale = new Vector3(Mathf.Abs(scale.x), scale.y, 1);
        newWeapon.transform.right      = transform.right;
        shotDir = newWeapon.transform.GetChild(0);
    }