Some condition with weapon model

Hello.

So, i’ve created a button for change weapon (OnGUI function) :

  		if(GUI.Button (Rect (xPlay,yPlay,heightButtonPlay,widthButtonPlay), "Change weapon")){
  			if(targetScript.WeaponActive == 1){
			targetScript.WeaponActive = 2;
			}else if(targetScript.WeaponActive == 2){
			targetScript.WeaponActive = 3;
			}else if(targetScript.WeaponActive == 3){
			targetScript.WeaponActive = 1;
			}
		}

In the inspector, when i click on the button, the value of WeaponActive change, but not the model, but my script seems good (update function):

if(WeaponActive == 1){
	Sword1.renderer.enabled = true;
	Sword2.renderer.enabled = false;
	Sword3.renderer.enabled = false;
}
if(WeaponActive == 2){
	Sword1.renderer.enabled = false;
	Sword2.renderer.enabled = true;
	Sword3.renderer.enabled = false;
}
if(WeaponActive == 3){
	Sword1.renderer.enabled = false;
	Sword2.renderer.enabled = false;
	Sword3.renderer.enabled = true;
}

if(WeaponActive == 0){
NoWeapon = true;
	Sword1.renderer.enabled = false;
	Sword2.renderer.enabled = false;
	Sword3.renderer.enabled = false;
}

In the game i just see the WeaponActive = 1, because it’s my base value (in my start function) :

WeaponActive = 2;
NoWeapon = false;

What is the problem ? :confused:

Sorry for my bad english, i’m french.

3 Answers

3

why are you using .render.enabled?

just use SetActive(false); or SetActive(true);

Because i don’t know that ^-^

But I have try and i have the same problem.

EDIT: When I do manually a thing like this :

if(WeaponActive == 1){
Sword1.SetActive(true);
Sword2.SetActive(false);
Sword3.SetActive(false); }

It’s work in game, but when I press the button, the model of the weapon don’t change.

Sword1 is the variable for the GameObject right? Also next time post using the comments, not another answer

Okey sorry, yes it's the GameObject, just see : Sword1 = GameObject.Find("Sword1");

ok would you mind posting the whole script? or atleast that section, because i see nothing wrong with those 3 lines.