I’m still relatively new to unity, I’m trying to create a script to handle weapon information (like ammunition, damage, name etc) and handle weapon switching. My script is giving me the above error but not providing a line so I don’t know where it is occuring
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weaponManager : MonoBehaviour
{
public GameObject weaponHolder;
public Transform[] weaponHolderChildren = new Transform[9];
public List<GameObject> weaponObjects = new List<GameObject>(9);
public List<weaponClass> weapons = new List<weaponClass>(9);
public GameObject testObject;
int currentWeapon;
void Start()
{
weaponHolderChildren = GetComponentsInChildren<Transform>();
for (int i = 0; i < weaponObjects.Count; i++)
{
weaponObjects.Add(weaponHolderChildren*.gameObject);*
}
int currentIndex = 0;
foreach (GameObject weaponGameObject in weaponObjects){
weapons[currentIndex].weaponObject = weaponGameObject;
weapons[currentIndex].weaponName = weaponGameObject.GetComponent().weaponName;
weapons[currentIndex].damage = weaponGameObject.GetComponent().damage;
weapons[currentIndex].maxAmmo = weaponGameObject.GetComponent().maxAmmo;
weapons[currentIndex].ammoPickupSize = weaponGameObject.GetComponent().ammoPickupSize;
weapons[currentIndex].ammoPickupName = weaponGameObject.GetComponent().ammoPickupName;
currentIndex++;
}
currentWeapon = 0;
setActiveWeapon(currentWeapon);
}
void Update()
{
}
public void testForWeaponInput()
{
}
public void setActiveWeapon(int passedWeapon)
{
int currentIndex = 0;
foreach (weaponClass weapon in weapons)
{
if (currentIndex == passedWeapon)
{
weapon.weaponObject.SetActive(true);
}
else
{
weapon.weaponObject.SetActive(false);
}
}
}
}