Thanks to the amazing ardizzle for solving this! To me, working through this post is EXACTLY what this community is all about!
Edit: You know, I realize that maybe I’m asking the wrong question, and making this far too complicated. Let me ask this:
Is there a way to call a function multiple times in the same script? Right now, if I try I get a “StackOverflow” error.
The gist of my post below is I have three weapons. (According to the script, four, but one of them is simply an empty hand) By pressing the “Weapon Switching” button on the gamepad the weapon switches to the next weapon, ironically enough. The issue is that when I get to the final weapon it stays on that rather than cycling back to the first one (Empty hand) and starting the process over. So my latest thought is if I could just call the original function again (SelectWeapon, or even Update) in the script below, that might work. I can’t believe how incredibly frustrated I am by this, it seems like it would be such a simple thing to do, but this issue has dogged me for a month now. [END OF EDIT]
Hello again,
I’ve been having some success using a weapon switching script, but need to cycle completely through the player’s weapons. Right now player is able to cycle from 1 - 4, but then stays at weapon 4. I need them to be able to restart at 1 once they have 4 equipped, and have pressed the “weapon switching” controller button. I tried calling “Update” again, only to get a stack overflow. (ok, that makes sense, but was willing to try it) Any help is greatly, and humbly, appreciated. God bless.
var Weapon01 : GameObject;
var Weapon02 : GameObject;
var Weapon03 : GameObject;
var Weapon04 : GameObject;
static var weaponready = false;
static var swordready = false;
static var cameraready = false;
function Update () {
if (Input.GetButtonDown("Weapon Switch")) {
if (weaponready == true)
SelectWeapon();
}
}
function SelectWeapon () {
if (Weapon01.active == true)
{
if (WeaponInv.Club >=1)
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(true);
Weapon03.SetActiveRecursively(false);
Weapon04.SetActiveRecursively(false);
}
if (Input.GetButtonDown("Weapon Switch")) {
if (WeaponInv.Sword >=1)
if (swordready == true)
SwordSelect();
}
}
function SwordSelect () {
if (Weapon02.active == true)
{
if (WeaponInv.Sword >=1)
if (swordready == true)
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(false);
Weapon03.SetActiveRecursively(true);
Weapon04.SetActiveRecursively(false);
}
if (Input.GetButtonDown("Weapon Switch")) {
if (cameraready == true)
CameraSelect();
}
}
function CameraSelect () {
if (Weapon03.active == true)
{
if (WeaponInv.Camera >=1)
if (cameraready == true)
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(false);
Weapon03.SetActiveRecursively(false);
Weapon04.SetActiveRecursively(true);
}
if (Input.GetButtonDown("Weapon Switch")) {
Update();
}
}