This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

matheusfig1

Gun Attachments System

79 posts in this topic

It do a code, ex : If  "weapon(var String) " = W, it active the weapon there is "W" weapon.You just have to do a script that turn the string into a letter,ex:

 

var Code : GameObject;

 

if( GUI.button... ){

 

Code = transform.gameobject.GetComponent( "Coder" ).Weapon = Code = transform.gameobject.GetComponent( "Coder" ).Weapon = "W";

 

}

 

So, here is the code:

 

Aim = Aim Rail ex: ACOG

Front = Like Silencer and others

Side = Side Rail ex: Laser or Flash

Down = Down Rail ex: Vert Grip

Please login or register to see this code.

The Script that read the code:

 

Transform M4A1, ACWR,VAL to Your Guns like: Ak-47,G36,Scar-H.

 

Turn the "Letters" that are equal to a weapon or an attachment to your letters(That letters that are in the other script).

 

Understand the next script : The Attachments are on the gun the only have to be activated.

 

The Script That turn the code into fitting attachments:

Please login or register to see this code.

Say the errors that you had and I will say what you should do.

 

When quit game, remember to do this line before :

 

Save();

 

In the my project it stayed like that:

 

 

gprh.png

 

An exemple package that i made for help :

 

Please login or register to see this link.

Edited by matheusfig1
1 person likes this

Share this post


Link to post
Share on other sites

Thanks for sharing the script. However, .active is obsolete in Unity 4.x so use SetActive instead of that.

1 person likes this

Share this post


Link to post
Share on other sites

Oh my god, are you really using GameObject.Find and FindChild in every frame? Either cache it in the start, or best of all, make new variables for those and expose in the inspector for you to assign.

4 people like this

Share this post


Link to post
Share on other sites

Yes, because you are searching for the object dynamically on every frame. It's better to just do it at the start function and store it in a variable.

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

I think its the same, just change the amount of "vars" in the inspector.

Share this post


Link to post
Share on other sites

Okay, it's up to you. I don't really care either way but GameObject.Find and FindChild are a lot slower.

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

Ok, But it wasnt for me,  thanks to try to help improving this

Edited by matheusfig1

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

 

it is not a in game custom attachments, put in a diferent scene the first you have to config an other script to "config" the string, like: var Weapon = "W"; W is the letter of one of your weapons. in the second script, put in your player camera and put all the weapon into the camera ( as a child ), and disable them, config the vars of the script and in the other scene you select your attachments and when you load the 2° scene it will enable the selected weapon and the current attachments

Edited by matheusfig1

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

it is on the final of the topic but here you are:

 

gprh.png

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

would you be able to make an example project or do a video as i still don't understand, i have tried and it still does not seem to be working 

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

sorry, in dont understand, I do a fps kit or put into other fps kit(if other i think so)

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

dont need i did a package for non - comercial use(if you edit, you can use for comercial porpouse , dont need edit the scripts and th gun):

 

Please login or register to see this link.

Edited by matheusfig1

Share this post


Link to post
Share on other sites

I will and thank you, i have being struggling for ages to finding attachment script  !

also how would i make a button to make it then go on to the game. and how would i make it so then the model would show on my game?

sorry im asking to many questions 

Edited by yellowflashxd

Share this post


Link to post
Share on other sites

How would i implement this to the fps kit, so when i customized the weapon and go on next, how would i make the guy pull out the gun w/ attachments? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now