dont know where else to ask this but im wondering how to set info to a struct from another C# script kinda need to do this in order to get things rolling again so any one with any info on this would be great
mainly just need to know how to find the index of something with in a struct... heres a sample of the code im working with . public struct Weapons { public bool available; public WeaponType type; public WeaponBase weapon, subWeapon; public Rigidbody dropout; }
public int maxWeapons = 2; public AudioClip switchWeapon, switchShootingMode, subWeaponOnOff, switchProjectile; public GameObject newwep; public Weapons[] weapons;
Accessing data in a struct is the same as in a class.
What do you want to do/access in the struct?
Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found. If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
basically im trying to set a game object in the struct at its index when i spawn the wep with ork but im having a hell of a time figuring it out if you got time an are willing mind taking a look at the code below an see what you think? the wepaonbase is what im trying to set at run time
Wild guess - your weaponIndex is set to -1 in the Awake function, usually next would be the Start function, where you use it to set cnt, which indexes the array, which will cause an out of bounds exception (i.e. tries to access weapons[-1]).
Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found. If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
No, every array goes from 0 to array.Length-1 > everything outside of that range will throw an error. You'll need to start at index 0.
Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found. If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
ok so after a long bout of messing with this stupid thing finally wrote a script to make it work problem was he has everything set to private that delt with the weapons array so after i figured that out i was able to get it to work like i wanted -_- just sucks that it took this long to figure out... so thanks gil for looking at a non ork script and giving me some advice on it
public struct Weapons
{
public bool available;
public WeaponType type;
public WeaponBase weapon, subWeapon;
public Rigidbody dropout;
}
public int maxWeapons = 2;
public AudioClip switchWeapon, switchShootingMode, subWeaponOnOff, switchProjectile;
public GameObject newwep;
public Weapons[] weapons;
and lower theres
for( int cnt = weaponIndex; cnt < weapons.Length; cnt++ )
if( cnt != weaponIndex && weapons[ cnt ].available )
{
weaponIndex = cnt;
StartCoroutine( ChangeWeapon() );
break;
}
my problem is i cant seem to figure out how to grab anything from the index
Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games
or check out the face book page here https://www.facebook.com/ForeLoreGames
What do you want to do/access in the struct?
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Deleted
Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games
or check out the face book page here https://www.facebook.com/ForeLoreGames
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games
or check out the face book page here https://www.facebook.com/ForeLoreGames
You'll need to start at index 0.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Deleted
i need to place it at ta certain index so not sure how to go about it
Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games
or check out the face book page here https://www.facebook.com/ForeLoreGames
Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games
or check out the face book page here https://www.facebook.com/ForeLoreGames