- Home /
FPS custom weapons & characters?
Okay here is my questions; firstly is it possible to have custom characters or weapons without unity pro? perhaps via scripting? My Team desires to work on a fps short game featuring the custom weapons, similar too army of two, also could that apply to characters as well?
Everything is possible via scripting. What do you mean, actually, by 'custom' weapons and characters? Do you mean player-created content?
Well, I am not sure about player created content, have yet to see that in any game that i have played. If it werent for the risk of glitches or viruses i would say why not. But i mean like attaching scopes, switching barrel types, stocks, ammo types, silencers etc. for example the silenced shotgun saw that on redjacket show. Then again...perhaps if some players had 3d skills and wanted to upload usable 3d models....perhaps another weapon type or something perhaps have a submission process...but otherwise i just meant switching barrels clips etc that change the weapon power, speed, distance Loudness etc.
Answer by GoThXoRd · Feb 29, 2012 at 01:00 AM
Yes. no scripting required. If they are FBX files, you can just drag them from explorer into the Unity Project pane. Scripting will be required to make the weapons fire though.
Answer by syclamoth · Feb 29, 2012 at 01:26 AM
I'm not sure where you got the idea that you would require unity Pro to do any of this stuff, but anyway...
If you want to be able to switch between various weapons, there are several well-known methods for doing this. Search this site, I'm sure you'll come up with at least 10 similar problems.
For customisable weapons, you could do someting like this
[System.Serializable]
public class Weapon
{
public float damage;
public float recoil;
public bool hasScope;
public bool hasLamp;
public bool hasProjectile;
public GameObject projectilePrefab;
public Renderer weaponRenderer;
}
Make all the 'weaponRenderer' fields be renderers, children of the main camera, that are the correct objects in the correct positions.
Then, in your firing script, have somthing like this:
public Weapon shotgun;
public Weapon rifle;
public Weapon bfg;
Weapon curWeapon;
void Awake()
{
curWeapon = shotgun;
}
void FireGun()
{
Target.takeDamage(curWeapon.damage);
// do other things based on 'curWeapon.whatever'
}
void ChangeWeapon(Weapon nextGun)
{
curWeapon.weaponRenderer.enabled = false;
curWeapon = nextGun;
curWeapon.weaponRenderer.enabled = true;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
ChangeWeapon(shotgun);
}
if(Input.GetKeyDown(KeyCode.Alpha2))
{
ChangeWeapon(rifle);
}
if(Input.GetKeyDown(KeyCode.Alpha3))
{
ChangeWeapon(bfg);
}
}
Now, you can add as much functionality as you like to the 'Weapon' class, but this should get you started with basic weapon switching and customisation. Remember that you can modify the weapons at runtime- if your shotgun gets an addon that increases its damage and decreases its recoil, you can use
shotgun.damage = shotgun.damage + damageModAmount;
shotgun.recoil = shotgun.recoil + recoilModAmount;
Same for adding scopes etc:
void RaiseScope(bool up)
{
if(!curWeapon.hasScope)
{
return;
}
Camera.main.fieldOfView = up?35:80;
}
Remember to reset the scope before you change weapons! It's as simple as adding the line
RaiseScope(false);
immediately before you switch guns.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Weapon switching using array 1 Answer
How to draw an arrow from fps contoller 1 Answer
Players unexpectedly change positions 0 Answers
How to make an ingame weapon/ammo shop 0 Answers