all you would have to do is setting the values.
now i want to instantiate each weapon from the item array based on a random number (0 - array lenght)
raising it out of the mystery box after the animation (opening the box) is done. and clearing it when its not picked up.
how would i do that?
what i have now is this:
public MysteryBoxItems[] items;
void Update()
{
for (int i = 0; i < items.Length; i++)
{
MysteryBoxItems insertedItems = items[i];
Debug.Log("found item with the name: " + insertedItems.itemName);
}
}
and the mysteryBoxItems script contains this:
using UnityEngine;
[System.Serializable]
public class MysteryBoxItems{
[Header("item info")]
public string itemName;
public GameObject Item;
[Space]
[Header("ammo")]
public int ammoPerRound;
public int maxRounds;
[Space]
[Header("display")]
public Vector3 rotation;
public Vector3 scale;
}
can someone help me?
(the animations and all work. just need help with the instantiating the weapons correctly with the given values)
You don’t need to for-loop through the items if you’re just picking one of them at random.
int i = Random.Range(0, items.Length);
MysteryBoxItems mbItem = items[i];
Instantiating the weapon should be pretty straightforward, but
takes an extra step. It will depend on how your spawned prefab is set up. Assuming you have a script that will be attached to any prefab you’d spawn here:
Well, you’ve got some unnecessary local variables in there (lines 21-24 are unnecessary; those values can be inserted directly into the function calls without needing to assign them to a local variable first). Other than that, not really.