I want to spawn mags based on the amount of variable mags I have left. Like if I have 1 mag then 1 mag appears but if I have 2, then 2 appear. This is my code : using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class shooting : MonoBehaviour
{
public double magbullets = 10;
public double mags = 2;
public Transform bulletSpawnPoint;
public GameObject bulletPrefab;
public Transform spawnLocation;
public float speed = 1f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.R))
{
if (mags > 0)
{
if (magbullets < 1)
{
mags -= 1;
magbullets += 10;
GetComponent<Animation>().Play("reload");
}
}
}
if (Input.GetMouseButtonDown(0))
{
if (magbullets > 0)
{
var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
bullet.GetComponent<Rigidbody>().velocity = bulletSpawnPoint.forward * speed;
magbullets -= 1;
}
}
}
}