|
i have this script for weapon switching and was thinking couldn't you make it an OnCollisionEnter to change the weapon so here is what i have. { // Select the first weapon SelectWeapon(0); } function Update() { // Did the user press fire? if (Input.GetKeyDown("1")) { SelectWeapon(0); }
(comments are locked)
|
|
okay. To select a weapon using OnCollisionEnter use this in the FPS controller and in the same script that has the function SelectWeapon : You can either have different tags like aColliderThatChangesToWeaponNumber0, aColliderThatChangesToWeaponNumber1, aColliderThatChangesToWeaponNumber2 and so on that individually tell the FPS controler to change the weapon. Or its better that you create one more code that can be applied to every collider that can change the weapon of the FPS controller and this code stores a number like 0,1,2 and it can be used like this. This is lets say this is a code called "colliderScript.js" which is attached to all the colliders that can change the weapon of the player. Plus, mark the colliders as Trigger: Now the code that you have above will have this function. Add this function to the same script that has the selectWeapon function and remove the previous OnTriggerEnter function : I hope this helps! PS : not tried this code in Unity so reply if you get any error(s). error Assets/Pickup.js(4,21): BCE0024: The type 'SelectWeapon' does not have a visible constructor that matches the argument list '(int)'.
Jan 14 '12 at 06:19 PM
conflictbliz
what is the pickup.js script? Is it the one that has selectWeapon function? Anyways, I made some changes in the code above, go through I just tried the previous code in Unity and found some problem and it worked well when the colliders were triggers.
Jan 14 '12 at 07:18 PM
vatsalAtFEI
could you please tell me what script goes on witch because its not that clear, i got the collideScript so when you hit that it should change the weapon. Then there is the selectWeapon script which changes the weapon once collided with the collide script. I just dont know about the function script you told me to add, where does it go, be more specific?
Jan 14 '12 at 10:47 PM
conflictbliz
yeah the script with the function SelectWeapon should have the OnTriggerEnter function because the OnTriggerEnter function calls the SelectWeapon and thus they need to be in the same script.
Jan 15 '12 at 06:15 AM
vatsalAtFEI
it should work but for SelectWeapon i am getting these errors, Assets/SelectWeapon.js(4,21): BCE0024: The type 'SelectWeapon' does not have a visible constructor that matches the argument list '(int)'. Assets/SelectWeapon.js(6,21): BCE0024: The type 'SelectWeapon' does not have a visible constructor that matches the argument list '(int)'. Assets/SelectWeapon.js(10,17): BCE0005: Unknown identifier: 'other'. Assets/SelectWeapon.js(11,33): BCE0024: The type 'SelectWeapon' does not have a visible constructor that matches the argument list '(int)'. Assets/SelectWeapon.js(14,33): BCE0024: The type 'SelectWeapon' does not have a visible constructor that matches the argument list '(int)'.
Jan 15 '12 at 07:18 AM
conflictbliz
(comments are locked)
|

You've been a registered user of this site since July and you still haven't caught on to the proper code formatting concept? C'mon.
i have just not with networking, everytime i try to make a script its either a error saying unknown identifier or somthing silly which i cannot fix.
please format the code that you post in a more readable manner. Select the code and press the 0101 button at the top of the question window to do this.
FTFY:
Now what exactly it is you're asking for?