Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

This is the script I used to throw chairs if this helps anyone :) 


public class WeaponManager : MonoBehaviour

{

    public GameObject[] weapons;

    public Transform spawnPoint;

    public GameObject currentWeapon;

    public bool isHandEmpty;

    public bool canThrow;

    public int weaponAmount;

    public float weaponCooldown;

    public Text weaponTextAmount;

    // Start is called before the first frame update

    void Start()

    {

        isHandEmpty = true;

        SpawnWeapon();

    }

    // Update is called once per frame

    void Update()

    {

        weaponTextAmount.text = "Weapons left: " + weaponAmount.ToString();

        if (weaponAmount <= 1)

        {

            canThrow = false;

        }

        else if (weaponAmount >= 2)

        {

            canThrow = true;

        }

        if (Input.GetKey(PlayerControls.Throw))

        {

            if (canThrow == true && isHandEmpty == false)

            {

                currentWeapon.transform.parent = null;

                currentWeapon.GetComponent<WrestlerWeapon>().ThrowWeapon();

                currentWeapon = null;

                StartCoroutine(spawningWeapon());

                isHandEmpty = true;

                weaponAmount--;

            }

        }

    }

    public void SpawnWeapon()

    {

        if (isHandEmpty == true)

        {

            GameObject spawnedWeapon = Instantiate(weapons[Random.Range(0, weapons.Length)], spawnPoint.position, spawnPoint.rotation);

            currentWeapon = spawnedWeapon;

            currentWeapon.transform.parent = spawnPoint.transform;

            isHandEmpty = false;

        }

    }

    IEnumerator spawningWeapon()

    {

        yield return new WaitForSeconds(weaponCooldown);

        SpawnWeapon();

    }

}