Hi,
I’m using the FPS prefab but I can’t,
figure a script for changing gun e.g. put
away one gun and take out another with different
properties and stuff.
Any suggestions?
Thanks,
Stuart
Hi,
I’m using the FPS prefab but I can’t,
figure a script for changing gun e.g. put
away one gun and take out another with different
properties and stuff.
Any suggestions?
Thanks,
Stuart
Still new myself but this is sort of how I planned on doing it…
var velocity = 30.0;
var projectileOne : Rigidbody;
var projectileTwo : Rigidbody;
var projectileThree : Rigidbody;
// ...and so on
private var currentProjectile : Rigidbody;
private var pNum=0;
function Update ()
{
if (Input.GetButtonDown ("SwitchWeapon")) {
pNum++;
if (pNum < 2) pNum=0;
}
if (Input.GetButtonDown ("Fire1"))
{
// setup the 'currentProjectile' before firing...
if (pNum == 0)
currentProjectile = projectileOne;
else if (pNum == 1)
currentProjectile = projectileTwo;
else if (pNum == 2)
currentProjectile = projectileThree;
else // just in case pNum is out of bounds somehow.
currentProjectile = projectileOne;
var shoot : Rigidbody = Instantiate (currentProjectile, transform.position, transform.rotation);
shoot.velocity = transform.rotation * Vector3.fwd * velocity;
}
}
…typed/compiled here, untested, use at your own risk, etc. HTH