Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Slasmir · Feb 08, 2012 at 10:04 PM · buttons

Problems with buttons all turning on or off at the same time

Hello i have a problem with my button prefab.

Im having diferent buttons all over my game, and its importent that i know if they are on or off. The button script where its turned on or off is in one script (Script A) where the activation of that scripts is in my player script (Script B).

So I need Script B to trigger a function on Script B. Pretty simple i got that to work, but its doing it on all the prefabs when im doing it this way.

Can someone write some code or explane how im changing my Boolean on onely one object insted of all the prefabs.

The button comes from a prefab with a script.

Thanks for your time reading this question.

Edit: Sorry for that, this is my fist question and not sure how to set it up i will give some code here:

Script B

     var UseScript                : GameObject;
     //*Public Variables End*
     
     
     
     function Update () 
     {    
         if((Input.GetKeyDown(controllsUse) && inUseRange) || (Input.GetKeyDown(controllsUse2) && inUseRange))
         {
             Use();
         }
     }
     
     function Use()
     {
         print("use");
         UseScript.GetComponent(JsObjectsButtons).UseButton();
     }
     
     function OnTriggerEnter (other : Collider)
     {
         if (other.tag == "Button")
         {
             print("In");    
             inUseRange = true;
         }
     }
     
     function OnTriggerExit (other : Collider)
     {
         if (other.tag == "Button")
         {
             print("Out");
             inUseRange = false;
         }
     }
 
 
 

    **Script A**
 //useable Objects
 
 //Public Variables
 var objKind     : int;
 
 //Private Variables 
 var isOn : boolean = false;
 function Update () 
 {
     UseButton();
 }
 
 public function UseButton()
 {
     if(isOn)
     {
         isOn = false;
         renderer.material.color = Color.blue;
     }
     
     else if(!isOn)
     {
         isOn = true;
         renderer.material.color = Color.green;
     }
     print(isOn);
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Slasmir · Feb 09, 2012 at 08:23 AM

I fixed it, as soon as i posted the code i saw the problem. i where editing the overall prefab not the single i have now added that the script changes ontrigger enter.

Enyways thanks alot for helping me how to post a question Aldonaletto, and for being nice to my bad post :)

Comment
Add comment · 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
1

Answer by aldonaletto · Feb 08, 2012 at 10:48 PM

You should post your code - how could we know what's wrong without seeing it?
Anyway, using the telepathic powers I developed in Unity Answers, I got a feeling that your problem may be caused by some static boolean variable.
A static variable is created only once, and is the same for all instances of the script - thus different prefabs will see the same value.
If my feeling is right, you still must edit your question and post the scripts A and B, because the solution will depend on how they are written - you may have to avoid static vars, or use some other trick to affect only the desired object.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Zombie Round Script Help 1 Answer

Spawn Script Not Working 1 Answer

Adding commands to buttons? 1 Answer

[SOLVED] Problem with "foreach". 1 Answer

Making A Script for my Switch 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