Hi There,
What I need is a switch board as such. I have Four objects (will be more) that i need to disappear and reappear. but only one will be rendererd at any given time.
To set the scene I have a character that has a two weapons, wood sword and a metal sword.
I’ve placed the two weapons in the characters hands and two in the weapon holder on his hip. At run time only one will be rendered, the wood sword on the hip.
The player presses a key to get the weapon out, the object in the hip is no longer rendered. The wood sword in hand is rendered. If the player presses the same key again he puts the weapon back.
The player presses a different key to switch weapons and the same process above but the wood sword is swapped to a metal sword.
here is the main Weapon.js code I’m using
var WoodOrMetal : int = 1;
//Wood = 1
//Metal = 2
var WeaponOutNow : boolean = false;
static var Changing : boolean = false;
static var Add : int = 0;
function Update ()
{
if(Add >= 4)
{
Changing = false;
Add = 0;
}
if (Input.GetKey("v") && Add == 0)
{
Changing = true;
TakeWeaponOut();
}
if(Input.GetKeyDown(KeyCode.B))
{
Changing = true;
SwitchWeaponNow();
}
}
function SwitchWeaponNow()
{
if(WoodOrMetal == 1)
{
WoodOrMetal = 2;
WoodOut.WoodOutTF = false;
WoodAway.WoodAwayTF = false;
MetalOut.MetalOutTF = false;
MetalAway.MetalAwayTF = true;
}
else
{
WoodOrMetal = 1;
WoodOut.WoodOutTF = false;
WoodAway.WoodAwayTF = true;
MetalOut.MetalOutTF = false;
MetalAway.MetalAwayTF = false;
}
}
function TakeWeaponOut()
{
if(WoodOrMetal == 1)
{
WoodNow();
}
if(WoodOrMetal == 2)
{
MetalNow();
}
}
function MetalNow()
{
if(WeaponOutNow == true)
{
MetalOut.MetalOutTF = true;
MetalAway.MetalAwayTF = false;
}
if(WeaponOutNow == false)
{
MetalOut.MetalOutTF = false;
MetalAway.MetalAwayTF = true;
}
SwitchOnOff();
}
function WoodNow()
{
if(WeaponOutNow == true)
{
WoodOut.WoodOutTF = true;
WoodAway.WoodAwayTF = false;
}
if(WeaponOutNow == false)
{
WoodOut.WoodOutTF = false;
WoodAway.WoodAwayTF = true;
}
SwitchOnOff();
}
function SwitchOnOff()
{
if(WeaponOutNow == true)
{
WeaponOutNow = false;
}
else
{
WeaponOutNow = true;
}
}
Here is the WoodAway.js I’ve only added one as all four would flood this question. The other three js are the same except for the one static var ( it has a different name).
static var WoodAwayTF : boolean = false;
function Update ()
{
if(Weapon.Changing == true)
{
if(WoodAwayTF == true)
{
renderer.enabled = true;
}
if(WoodAwayTF == false)
{
renderer.enabled = false;
}
Weapon.Add ++;
}
}
As you can see it’s very long winded coding. It works but the objects flicker when changing and somtimes does’nt change. There must be a more reliable way of running this code. Any help or a little more understanding will be very helpful.