I’m making a gun customization scene for my game and i’m making is so that when you press a button some more buttons show up but when i try to click one of my buttons (They are planes not Gui) it starts repeating either the “BackButton” or the “MainButotn4”. When I click on a button while “MainButton4” is repeating “MainButton2” flashes then 4 keeps repeating. Anyone know how I can make it so that when one button is pressed it stays pressed and doesn’t repeat. Here are me scripts:
Game Logic:
var MainSightID : int = 0;
var MainMuzzleID : int = 0;
var MainGuns : int = 0;
var MainSubButtons : int = 0;
function Update () {
}
Button Logic:
var SubButtons : int = 0;
var AssultRifleACWR : GameObject;
var PistolM9 : GameObject;
var ShotgunMCS : GameObject;
var SniperBarret : GameObject;
var GameLogicObj : GameObject;
function Awake(){
GameLogicObj = GameObject.FindGameObjectWithTag("Game_Logic");
}
function Update () {
Debug.Log (SubButtons);
SubButtons = GameLogicObj.GetComponent("Game_Logic").MainSubButtons;
if (SubButtons == 0){
AssultRifleACWR.SetActive(false);
PistolM9.SetActive(false);
ShotgunMCS.SetActive(false);
SniperBarret.SetActive(false);
}
if (SubButtons == 1){
AssultRifleACWR.SetActive(true);
PistolM9.SetActive(false);
ShotgunMCS.SetActive(false);
SniperBarret.SetActive(false);
}
if (SubButtons == 2){
AssultRifleACWR.SetActive(false);
PistolM9.SetActive(true);
ShotgunMCS.SetActive(false);
SniperBarret.SetActive(false);
}
if (SubButtons == 3){
AssultRifleACWR.SetActive(false);
PistolM9.SetActive(false);
ShotgunMCS.SetActive(true);
SniperBarret.SetActive(false);
}
if (SubButtons == 4){
AssultRifleACWR.SetActive(false);
PistolM9.SetActive(false);
ShotgunMCS.SetActive(false);
SniperBarret.SetActive(true);
}
}
Button Script:
var GameLogicObj : GameObject;
var ButtonID : String = "";
function Awake(){
GameLogicObj = GameObject.FindGameObjectWithTag("Game_Logic");
}
function OnMouseEnter (){
renderer.material.color = Color.gray;
}
function OnMouseExit (){
renderer.material.color = Color.white;
}
function Update (){
if(Input.GetMouseButtonDown(0)){
if(ButtonID == "BackButton"){
GameLogicObj.GetComponent("Game_Logic").MainSubButtons = 0;
}
}
if(Input.GetMouseButtonDown(0)){
if(ButtonID == "MainButton1"){
GameLogicObj.GetComponent("Game_Logic").MainSubButtons = 1;
}
}
if(Input.GetMouseButtonDown(0)){
if(ButtonID == "MainButton2"){
GameLogicObj.GetComponent("Game_Logic").MainSubButtons = 2;
}
}
if(Input.GetMouseButtonDown(0)){
if(ButtonID == "MainButton3"){
GameLogicObj.GetComponent("Game_Logic").MainSubButtons = 3;
}
}
if(Input.GetMouseButtonDown(0)){
if(ButtonID == "MainButton4"){
GameLogicObj.GetComponent("Game_Logic").MainSubButtons = 4;
}
}
}