Problem about shop and weapon switching
hi all i have this problem, i have a script that change weapon and works good.. the problem is that if i want to deactivate a weapon from the inspector it will force change for the script that set active the weapon.. i need that if i deactivate it will change only the weapon available that i set active.. i need this for a shop that i have that set active it when buyed.. let me know if i and how can i change this script. the script is this:
using System.Collections; using System.Collections.Generic; using UnityStandardAssets.CrossPlatformInput; using UnityEngine;
public class WeaponSwitching : MonoBehaviour {
public int selectedWeapon = 0;
// Start is called before the first frame update
void Start()
{
selectWeapon ();
}
// Update is called once per frame
void Update()
{
int previousSelectedWeapon = selectedWeapon;
if (CrossPlatformInputManager.GetButtonDown("Weapon+"))
{
if (selectedWeapon >= transform.childCount - 1)
selectedWeapon = 0;
else
selectedWeapon++;
}
if (CrossPlatformInputManager.GetButtonDown("Weapon-"))
{
if (selectedWeapon <= 0)
selectedWeapon = transform.childCount - 1;
else
selectedWeapon--;
}
if (previousSelectedWeapon != selectedWeapon){
selectWeapon();
}
}
void selectWeapon()
{
int i = 0;
foreach (Transform weapon in transform)
{
if (i == selectedWeapon)
weapon.gameObject.SetActive(true);
else
weapon.gameObject.SetActive(false);
i++;
}
}
}
Your answer
Follow this Question
Related Questions
Switching items - can't detect a crazy loop that is happening. 1 Answer
How to Switch GameObjects (Weapons) by reaching a specific amount of score? 0 Answers
Weapons Names And Models Licensing 1 Answer
Scene Switching problem. Scene becomes black when it changes 2 Answers
script enable=false 3 Answers