- Home /
Weapon system with a class
The question i have is. I have a class with all possible things i will need for the weapon how would i go about creating an index of these weapons and select them with the mouse scroll wheel and only allow them to be selected if they have been bought here is my code and it is literally just the weapon class i hope someone can point me in the right direction
var gunList : Gun[];
class Gun
{
var name : String;
var isSelected : boolean;
var canUserShoot : boolean;
var shootForce : float;
var ammo : int;
var bullet : GameObject;
var bullet2 : GameObject;
var bullet3 : GameObject;
var bulletHolder1 : Transform;
var bulletHolder2 : Transform; // only use these if the gun has more then one barrel
var bulletHolder3 : Transform; // only use these if the gun has more then one barrel
var shootSound : AudioClip;
var cost : int;
var unlocked : boolean;
var shootEffect : Transform;
var fireRate : float;
var currentWeapon : int;
var weaponModel : Renderer;
}
function NextWeapon()
{
}
function PreviousWeapon()
{
}
function SwapWeapon()
{
}
// i dont know if this is possible but create and index of the weapons and say something like raygun = 1 then when the player uses the mouse scroll wheel increase the number
// Then when it gets to the max reset the number to 1 which will be the raygun
// We also need to disable the renderer of unused guns
// and make sure that only the correct values for the guns are used. No point in having a rocket launcher the firs rockets and lasers would be pretty cool though:)
Please select all your code and push the 1010101 button to code it for us next time =).
As for the question, check out the Input methods in the API they have stuff on the mouse wheel (I believe).
I did use the 10101 button i think it is chrome as it only happens with that. I have looked into the API and found info about the mouse it's just i am new to indexing things like weapons and so forth. Thanks
Answer by Justin Warner · Dec 08, 2011 at 05:03 AM
Well, you have your array of gun's. Now make a variable for position in that array.
On Input scroll wheel up, increase that position, (On Update() check if it's = to length, if so, reset to 0, also check if it's
To get this Input, we look at the API. However, because this "could" be weird, I'll just Google:
So from this, we get: http://answers.unity3d.com/questions/26649/scrollwheel-input-not-detected-in-script.html
Now, we have our axis.
So simply, in the Update() put in the if input is scrollwheel up, do this, if down, do that.
Now, whether it goes up or down, that same search got us: http://answers.unity3d.com/questions/13485/implementing-the-scrollwheel.html
From here, we can see positive = up, negative = down, so now you can solve the rest by yourself.
Just walked you through basically how to answer most any questions =).
Hope this helped! Have a good night!