private void SetupAvailableWeapons() { //Add all available weapons based on the weapon templates that were set in the inspector. // Each weapon template has a corresponding weapon class, any unrecognised templates wil throw an error availableWeapons = new Weapon[availableWeaponTemplates.Length]; for (int i = 0; i < availableWeaponTemplates.Length; i++) { if (availableWeaponTemplates[i] is GunWeaponTemplate gunTemplate) { availableWeapons[i] = new GunWeapon(this, gunTemplate); } else if (availableWeaponTemplates[i] is MeleeWeaponTemplate meleeTemplate) { availableWeapons[i] = new MeleeWeapon(this, meleeTemplate); } else if (availableWeaponTemplates[i] is GrenadeWeaponTemplate grenadeTemplate) { availableWeapons[i] = new GrenadeWeapon(this, grenadeTemplate); } else if (availableWeaponTemplates[i] is PrototypeWeaponTemplate prototypeTemplate) { availableWeapons[i] = new PrototypeWeapon(this, prototypeTemplate); } else { Debug.LogError("Unrecognised weapon type at setup: " + availableWeaponTemplates[i].GetWeaponName()); } } }
//Constructor public ThrownGrenade(GrenadeWeapon grenadeParent, float delay, Transform transformHead) { m_grenadeParent = grenadeParent; m_delayTimer = delay; //Create the GameObject for this therown grenade and position it just in front of the player to start m_goThrow = Object.Instantiate(grenadeParent.m_grenadeTemplate.GetThrowGameObject(), transformHead); m_goThrow.transform.localPosition += new Vector3(0f, 0f, grenadeParent.m_template.GetVisualOffset().z); m_goThrow.transform.SetParent(null); //Give it a velocity based on the value set in the weapon's template m_goThrow.GetComponent <Rigidbody>().velocity = transformHead.forward * grenadeParent.m_grenadeTemplate.GetThrowVelocity(); }