void Init() { if (init) { return; } init = true; //AbilityManager.SetupAbility(abilityList); if (!weaponInitiated) { weaponInitiated = true; for (int i = 0; i < weaponList.Count; i++) { GameObject obj = MountWeapon((GameObject)Instantiate(weaponList[i].gameObject)); weaponList[i] = obj.GetComponent <Weapon>(); weaponList[i].Reset(); if (i > 0) { obj.SetActive(false); } if (perk != null) { weaponList[i].SetPlayerPerk(perk); } } if (weaponList.Count == 0) { GameObject obj = MountWeapon(null, "defaultObject"); weaponList.Add(obj.AddComponent <Weapon>()); weaponList[0].aStats.damageMax = 2; weaponList[0].Reset(); obj = MountWeapon(GameObject.CreatePrimitive(PrimitiveType.Sphere), "defaultShootObject"); obj.AddComponent <ShootObject>(); obj.SetActive(false); obj.transform.localScale = new Vector3(.2f, .2f, .2f); GameObject soObj = (GameObject)Instantiate(Resources.Load("Prefab_TDSTK/DefaultShootObject", typeof(GameObject))); soObj.SetActive(false); weaponList[0].shootObject = soObj; weaponList[0].InitShootObject(); } } TDS.SwitchWeapon(weaponList[weaponID]); }
public void SwitchWeapon(int newID) { weaponList[weaponID].gameObject.SetActive(false); weaponList[newID].gameObject.SetActive(true); if (weaponList[newID].currentClip == 0 && GameControl.EnableAutoReload()) { weaponList[newID].Reload(); } TDS.SwitchWeapon(weaponList[newID]); weaponID = newID; }
public void RemoveWeapon() //used to remove temporary weapon only { if (weaponList.Count <= 1) { return; } if (weaponList[weaponID] != null) { Destroy(weaponList[weaponID].gameObject); } weaponList.RemoveAt(weaponID); weaponID = tempWeapReturnID; weaponList[weaponID].gameObject.SetActive(true); TDS.SwitchWeapon(weaponList[weaponID]); }
private int tempWeapReturnID = 0; //a cache to store the default weaponID when using temporary weapon public void AddWeapon(Weapon prefab, bool replaceWeapon = false, bool temporary = false, float temporaryTimer = 30) { GameObject obj = MountWeapon((GameObject)Instantiate(prefab.gameObject)); //replace weapon and temporary are mutually exclusive if (replaceWeapon) { Destroy(weaponList[weaponID].gameObject); weaponList[weaponID] = obj.GetComponent <Weapon>(); TDS.NewWeapon(weaponList[weaponID], weaponID); } else if (temporary) { tempWeapReturnID = weaponID; weaponList[weaponID].gameObject.SetActive(false); if (weaponList[weaponID].temporary) { RemoveWeapon(); } weaponID = weaponList.Count; weaponList.Add(obj.GetComponent <Weapon>()); weaponList[weaponList.Count - 1].temporary = true; if (temporaryTimer > 0) { StartCoroutine(TemporaryWeaponTimer(weaponList[weaponList.Count - 1], temporaryTimer)); } } else { weaponID = weaponList.Count; weaponList.Add(obj.GetComponent <Weapon>()); TDS.NewWeapon(weaponList[weaponID]); } weaponList[weaponID].Reset(); TDS.SwitchWeapon(weaponList[weaponID]); }