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 Gilead7 · Aug 14, 2012 at 08:02 PM · c#texture2dguitexture

Toggle Only Works Once

Here is a weird one. I have my texture2d objects placed on the screen. It's supposed to change to another image when clicked. It worked before, but when I added another statement to the mix, it only changed once. After removing the addition, it still only does it once. Here is the code. If there is a better way of doing it, I'm glad to hear.

  public bool CombatMode;

public bool RangedMode; public Texture2D PeaceButton; public Texture2D CombatButton;

void OnMouseDown() { if(PeaceButton) Mode (); if(CombatMode=true) {

if(RangedButton) RangedAttackMode();

if(AttackHackButton) HackAttack();

if(AttackSlashButton) SlashAttack();

if(AttackThrustButton) ThrustAttack();

if(ButtonUppercutOn) UppercutAttack(); } (What I want to happen is to enable the attack types if you are in combat mode. Can't figure out how to do that.)

if(CharacterButton) Mirror ();

if(CampButton) Camp();

if(JournalButton) Journal();

if(InventoryButton) Inventory(); }

 void Mode()

{ if(!CombatMode) {

guiTexture.texture=CombatButton; CombatMode=true;

Debug.Log("Combat Mode" +CombatMode); } else {

guiTexture.texture=PeaceButton; CombatMode=false; Debug.Log("Peace Mode" +CombatMode); } }

Thanks!

Comment
Add comment · Show 2
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 Muuskii · Aug 14, 2012 at 08:11 PM 1
Share

if(Combat$$anonymous$$ode=true) should actually SET Combat$$anonymous$$ode = true and then always returns true (by definition)

On a related note, the statement toggle = !toggle; is sometimes useful.

Also please format your code by selecting it and pushing the 101010 button at the top.

Thank you.

avatar image Gilead7 · Aug 15, 2012 at 03:59 PM 0
Share

Thanks! I appreciate it!

1 Reply

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

Answer by Gilead7 · Aug 16, 2012 at 08:40 PM

For those that have been following this, I finally have a working solution, which I will share.

     private bool isCombatMode=false;
     private bool isRangedMode=false;
     public Texture2D PeaceButton;
     public Texture2D CombatButton;
     public Texture2D ChopLabel;
     public Texture2D ChopButton;
     public Texture2D SlashLabel;
     public Texture2D SlashButton;
     public Texture2D ThrustLabel;
     public Texture2D ThrustButton;
     public Texture2D UppercutLabel;
     public Texture2D UppercutButton;
     public Texture2D RangedLabel;
     public Texture2D RangedButton;
     public Texture2D RangedButtonOn;
 
 
     
     //***********************************
     // Rects for Combat Menu            //
     //***********************************
 

private Rect chopLabelRect = new Rect(Screen.width/2-242, Screen.height-99, 90, 90);

private Rect slashLabelRect = new Rect(307, Screen.height-99, 90, 90);

private Rect thrustLabelRect = new Rect(217, Screen.height-99, 90, 90);

private Rect uppercutLabelRect = new Rect(127, Screen.height-99, 90, 90);

private Rect rangedLabelRect = new Rect(Screen.width/2-152, Screen.height-99, 90, 90);

private Rect peaceButtonRect = new Rect(Screen.width/2-60, Screen.height-100, 90, 90);

private Rect chopButtonRect= new Rect(Screen.width/2-242, Screen.height-99, 90, 90);

private Rect slashButtonRect= new Rect(307, Screen.height-99, 90, 90);

private Rect thrustButtonRect= new Rect(217, Screen.height-99, 90, 90);

private Rect uppercutButtonRect= new Rect(127, Screen.height-99, 90, 90);

private Rect rangedButtonRect= new Rect(Screen.width/2-152, Screen.height-99, 90, 90);

     void OnGUI()
     {
         if ( GUI.Button(peaceButtonRect, PeaceButton) ) 
         {
             CombatMode();      
 
         }
         
         
         if ( isCombatMode) 
         {
                GUI.Button(peaceButtonRect, CombatButton);
               if(GUI.Button(chopButtonRect, ChopButton))
                 HackAttack();
                if(GUI.Button(slashButtonRect, SlashButton))
                 SlashAttack();
                if(GUI.Button(thrustButtonRect, ThrustButton))
                 ThrustAttack();
                if(GUI.Button(uppercutButtonRect, UppercutButton))
             UppercutAttack();
             if(GUI.Button(rangedButtonRect,RangedButton))
             RangedMode();
 
         }
     else 
         {
 
               GUI.Label(chopLabelRect, ChopLabel);    
                GUI.Label(slashLabelRect, SlashLabel);    
                GUI.Label(thrustLabelRect, ThrustLabel);
                GUI.Label(uppercutLabelRect, UppercutLabel);
                GUI.Label(rangedLabelRect, RangedLabel);
             
         }
         
         if(isRangedMode)
         {
             GUI.Button(rangedButtonRect,RangedButtonOn);
         }
         
         
     }
        
         
     void CombatMode()
     {
          isCombatMode = ! isCombatMode;
         Debug.Log("Combat Mode is:" +isCombatMode);
     }
 
     void RangedMode()
     {
         isRangedMode=!isRangedMode;
         Debug.Log("Ranged Mode is:"+isRangedMode);
     }
 
     
     
     void HackAttack()
     {
         Debug.Log("Selected Hack Attack!");
     }
     
     void SlashAttack()
     {
         Debug.Log("Selected Slash Attack!");
     }
     
     void ThrustAttack()
     {
         Debug.Log("Selected Thrust Attack!");
     }
     
     void UppercutAttack()
     {
         Debug.Log("Selected Uppercut Attack!");
         
     }
     
     void RangedAttack()
     {
         Debug.Log("Selected Ranged Attack!");
     }
     
     
     
     }

Hope that helps someone!

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

8 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Enabling and Disabling GUI Textures 1 Answer

Distribute terrain in zones 3 Answers

How to make OnGUI Texture able to be clicked 1 Answer

Assigning script-generated textures 0 Answers


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