Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Gun Attachment System

Gun Attachment System

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Gun Attachment System on Sat Jan 03, 2015 5:12 pm

WalkerPointZero


Member [Lv. 3]
Member [Lv. 3]
Here's a little Gun Attactment System which i found by sufing the internet, please note that this is not mine all credit goes to Matheusfig1

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

Code:
var Weapon = "";
var Aim = "";
var Front = "";
var Side = "";
var Down = "";

function OnGUI () {

if(GUI.Button(new Rect(10,500,100,50), "Save")){

PlayerPrefs.SetString("GunSaved", Weapon);
PlayerPrefs.SetString("AimSaved", Aim);
PlayerPrefs.SetString("FrontSaved", Front);
PlayerPrefs.SetString("SideSaved", Side);
PlayerPrefs.SetString("DownSaved", Down);

}

if(GUI.Button(new Rect(120,500,100,50), "Quit")){

Application.LoadLevel("Menu");

}

}
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:
Code:

var Weapon = "";
var Aim = "";
var Front = "";
var Side = "";
var Down = "";

var M4A1 : GameObject;
var ACWR : GameObject;
var VAL : GameObject;

var AimAcog : GameObject;
var AimRed : GameObject;
var AimM16 : GameObject;
var AimACWR : GameObject;

var SideFlash : GameObject;
var SideLaser : GameObject;

var FrontSilencer : GameObject;
var FrontMHider : GameObject;

var DownGrip : GameObject;

var WeaponPos : Transform;

function Start () {

Weapon = PlayerPrefs.GetString("GunSaved");
Aim = PlayerPrefs.GetString("AimSaved");
Front = PlayerPrefs.GetString("FrontSaved");
Side = PlayerPrefs.GetString("SideSaved");
Down = PlayerPrefs.GetString("DownSaved");

}

function Update () {

//weaponload
if(Weapon == "A"){
M4A1.active = true;
}

if(Weapon == "B"){
ACWR.active = true;
}

if(Weapon == "C"){
VAL.active = true;
}

//WeaponSearchAndConfig

var Gun = GameObject.Find("Gun(Clone)");

if(Gun.active == false){
return;
}

AimAcog = Gun.transform.FindChild("ACOG").gameObject;
AimRed = Gun.transform.FindChild("RedDot").gameObject;
AimACWR = Gun.transform.FindChild("Normal").gameObject;
AimM16 = Gun.transform.FindChild("M16Aim").gameObject;

SideFlash = Gun.transform.FindChild("Flash").gameObject;
SideLaser = Gun.transform.FindChild("Laser").gameObject;

FrontMHider = Gun.transform.FindChild("Hider").gameObject;
FrontSilencer = Gun.transform.FindChild("Silencer").gameObject;

DownGrip = Gun.transform.FindChild("Grip").gameObject;

//aim load

if(Aim == "D"){
AimAcog.active = true;
}else{
AimAcog.active = false;
}

if(Aim == "L"){
AimRed.active = true;
}else{
AimRed.active = false;
}

if(Aim == "E"){
AimACWR.active = true;
}else{
AimACWR.active = false;
}

if(Aim == "F"){
AimM16.active = true;
}else{
AimM16.active = false;
}

//front load

if(Front == "I"){
FrontSilencer.active = true;
}else{
FrontSilencer.active = false;
}

if(Front == "J"){
FrontMHider.active = true;
}else{
FrontMHider.active = false;
}

//side load

if(Side == "G"){
SideFlash.active = true;
}else{
SideFlash.active = false;
}

if(Side == "H"){
SideLaser.active = true;
}else{
SideLaser.active = false;
}

//down load

if(Down == "K"){

DownGrip.active = true;

}else{
DownGrip.active = false;
}

}

Here's an Example Project to Help you out if you are stuck [You must be registered and logged in to see this link.]

View user profile

2 Re: Gun Attachment System on Sun Jan 04, 2015 4:57 am

developer23


Moderator
Moderator
These codes are from Armedunity.com XD Wink But there is the problem when you export the game the weapons are invisibles... I don't know why Razz I think that is the API Wink

View user profile http://masterdevelopers.altervista.org/

3 Re: Gun Attachment System on Sun Jan 04, 2015 8:24 am

WalkerPointZero


Member [Lv. 3]
Member [Lv. 3]
developer23 wrote:These codes are from Armedunity.com XD Wink But there is the problem when you export the game the weapons are invisibles... I don't know why Razz I think that is the API Wink

When you start the scene you need to click on a gun then then you should see it pop up if you dont i'll look into it and try to fix it

View user profile

4 Re: Gun Attachment System on Sun Jan 04, 2015 10:47 am

developer23


Moderator
Moderator
WalkerPointZero wrote:
developer23 wrote:These codes are from Armedunity.com XD Wink But there is the problem when you export the game the weapons are invisibles... I don't know why Razz I think that is the API Wink

When you start the scene you need to click on a gun then then you should see it pop up if you dont i'll look into it and try to fix it
Ok

View user profile http://masterdevelopers.altervista.org/

5 Re: Gun Attachment System on Mon Jan 05, 2015 1:00 am

Good find, good share!

View user profile http://www.youtube.com/user/misterninjaboy

6 Re: Gun Attachment System on Tue Jul 07, 2015 4:10 pm

Outboundstream4


Member [Lv. 2]
Member [Lv. 2]
Yes! Yes! Yes! Thank you very much i have been searching forever!

View user profile

7 Thank you! on Tue Jul 07, 2015 4:11 pm

Outboundstream4


Member [Lv. 2]
Member [Lv. 2]
thank you for this!

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum