Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
  • Help Room /
avatar image
0
Question by researchmore · Nov 05, 2020 at 08:11 PM · toggleboolkey

toggle animator bool when in a collider

Hello, Im fairly new to c# and can't find a way to apply a toggle on a bool. Thank you for your help!

I am trying to create an information zone. When the player enter a collider, a text appears saying "press use key" to read. Then an animation pulling the information text in and out the screen is controlled by a bool named "slide".

I would like to set the boolean controlling the animation to true or false with a single key while in the collider, so the player can either move away from the collider or press "use" again to exit the text.

With the following code I only press "use" once and move away from the collider to make disapear. I am sure there is a simple solution to this but smh can't apply it. Thanks again!!

   using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class OnTriggerLoadconversation : MonoBehaviour
     {
       [SerializeField] private Animator myAnimationController;
       public GameObject enterText;
     
       void Start()
       {
         myAnimationController.SetBool("slide", false);
         enterText.SetActive(false);      
       }
     
       // Update is called once per frame
       void OnTriggerEnter(Collider plyr)
       {
           if (plyr.gameObject.tag == "Player")
           {
             enterText.SetActive(true);
     
               if (Input.GetButtonDown("Use"))
               {
                 myAnimationController.SetBool("slide", true);
                 enterText.SetActive(false);
     
               }
           }        
       }

       void OnTriggerStay(Collider plyr)
       {
           if (plyr.gameObject.tag == "Player")
           {
     
               if (Input.GetButtonDown("Use"))
               {
                 myAnimationController.SetBool("slide", true);
                 enterText.SetActive(false);
     
                }
             }
       }

       void OnTriggerExit(Collider plyr)
       {
           if (plyr.gameObject.tag == "Player")
           {
             myAnimationController.SetBool("slide", false);
             enterText.SetActive(false);
     
          }
       }
     }
     
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 researchmore · Nov 08, 2020 at 10:39 AM

So I made it work with the following solution. It still seem a bit buggy. (for some reason it doesn't seem to work every time) I am open if any body has something more elegant :)

So this is applied to my collider object. The ui object (press x to display info) is called "enterText". The bool that animate the actual information text in and out screen is called "slide", and Is toggled false or true to make it move.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class OnTriggerLoadconversation : MonoBehaviour
 {
   [SerializeField] private Animator myAnimationController;
   public GameObject enterText;
 
   void Start()
   {
     enterText.SetActive(false);
     myAnimationController.SetBool("slide", false);
     }

    // Update is called once per frame
     void OnTriggerEnter(Collider plyr)
   {
       if (plyr.gameObject.tag == "Player")
       {
         enterText.SetActive(true);       
       }
   }

 void OnTriggerStay(Collider plyr)
   {
       if (plyr.gameObject.tag == "Player")
       {
             if (Input.GetButtonDown("Use"))
           {
    myAnimationController.SetBool("slide", !myAnimationController.GetBool("slide"));
    enterText.SetActive(!enterText.activeInHierarchy);
           }
         }
   }

    void OnTriggerExit(Collider plyr)
     {
         if (plyr.gameObject.tag == "Player")
         {
        enterText.SetActive(false);
        myAnimationController.SetBool("slide", false);
         }
     }
 }


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

210 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Toggle a bool on only one object at a time by tapping an object. 0 Answers

How to enable/disable an Icon depending on the bool state of a toggle. 0 Answers

Toggle Group to make a GameObject Active in Scene onClick 0 Answers

How do you keep a toggle highlighted/ load up a scene with the toggle in its highlighted state 1 Answer

How can I set a toggle to reverse the direction of a rotation? 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