Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KidGamingFTW · Sep 30, 2013 at 08:16 AM · buttonfps

When my button is pressed the action reapeats

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;
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by srancsik · Sep 30, 2013 at 08:41 AM

I think the problem is that in Button script you have the MainButton scripts in the function Update, which continues to run this script frame by frame (causing the flashing). Try put the whole content of the Button script function Update to funtion OnMouseEnter.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KidGamingFTW · Sep 30, 2013 at 09:17 AM 0
Share

I have tried that too (sorry I forgot to put it on my question) but when i do that I have to click outside the editor everytime a button is pressed.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

A node in a childnode? 1 Answer

Switch Camera On Button Press? 2 Answers

Loop animation on button hold 2 Answers

how to run Sprint 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges