FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionGun Attachment System

more_horiz
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.]

descriptionRe: Gun Attachment System

more_horiz
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

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

descriptionRe: Gun Attachment System

more_horiz
[You must be registered and logged in to see this link.] 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

descriptionRe: Gun Attachment System

more_horiz
[You must be registered and logged in to see this link.] wrote:
[You must be registered and logged in to see this link.] 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

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

descriptionRe: Gun Attachment System

more_horiz
Good find, good share!

descriptionRe: Gun Attachment System

more_horiz
Yes! Yes! Yes! Thank you very much i have been searching forever!

descriptionThank you!

more_horiz
thank you for this!
Permissions in this forum:
You cannot reply to topics in this forum