Question by
codedbythet · Nov 19, 2021 at 10:54 PM ·
triggernullweapon2d platformerweaponchanging
Bullet Prefab Switch Help
I have a player where player shoot script has a weapon array that I am trying to have empty.
I have a script that when the player triggers a collision the pickup script that has the bulletprefab is supposed to fill the Element0 and then change the bulletprefab to the bullet type it collided with. The problem is that if nothing is there, then it does not change. but if I have a bulletprefab already in place, it will switch correctly.
My question is how can I tell the trigger script that if there is no bulletprefab, to choose the one that it collided with?
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.GetComponent<WeaponPickup>() != null)
{
for (int i = 0; i < playerShootCode.ListOfWeaponPrefabs.Length; i++)
{
if (playerShootCode.ListOfWeaponPrefabs[i] == other.gameObject.GetComponent<WeaponPickup>().bulletPrefab)
{
playerShootCode.bulletPrefab = other.gameObject.GetComponent<WeaponPickup>().bulletPrefab;
}
}
Debu
empty.png
(13.8 kB)
Comment