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 /
avatar image
0
Question by kayakmtb · Mar 25, 2021 at 07:25 PM · buttonsupdate function

Turning a Panel on and off

Unity 2019.4.21f1

I have a VR app (Android 7 Device)that uses a raycast to open and close dialogue panels. I have one script that opens an instruction panel, and another to close it. Both scripts have a gaze timer built in. The problem is that the first time the panel opens fine. It closes fine the first time also. However, the second time i open the panel it opens briefly and then closes. I know that the issue is that once the close script is running, it continues to do so on update . However, having tried all sorts I cannot work out how to stop the close script until it is needed again. Any help would be gratefully received.

The Open script is attached to the Instruction button in the UI (note this is not a Unity button but an image with script attached)

The Close script is attached to the close button on the instruction panel. This is a Unity button.

Open Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class popUpInstOpen1 : MonoBehaviour
 {
     public GameObject InstructionPanel;
     public Image gazeCircle;
     public bool IsOpen = false; 
     private float totalTime = 2;
     private bool gvrStatus = false;
     private float gvrTimer = 0;
     void Start()
     {
         gazeCircle.fillAmount = 0;
     }
     
     void Update()
     {
                 
         if (gvrStatus)
         {
             gvrTimer += Time.deltaTime;
             gazeCircle.fillAmount = gvrTimer / totalTime;
             //Debug.Log("instructions open line 25");
         }
 
         if (gvrTimer > totalTime)
         {
             gazeCircle.fillAmount = 0;
             InstructionPanel.SetActive(true);
             gvrStatus = false;
             gvrTimer = 0;
             IsOpen = true;
             Debug.Log("instructions open line 36");
         }
     }
     public void OnPointerEnter()
     {
         gvrStatus = true;
         Debug.Log("instructions onpointer enter gvr true line 42");
     }
     public void OnPointerExit()
     {
         gvrStatus = false;
         gvrTimer = 0;
         gazeCircle.fillAmount = 0;
         Debug.Log("instructions onpointer exit gvr true line 49 - popupInstOpen");
      }
 }

Close Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class popupInstClose1 : MonoBehaviour
 {
     public GameObject InstructionPanel;
     public GameObject InstructionButton;
     public popUpInstOpen1 IsOpenCheck;
     public Image gazeCircle;
     private float totalTime = 2;
     private bool gvrStatus = false;
     private float gvrTimer = 0;
     void Start()
     {
         gazeCircle.fillAmount = 0;
     }
 
     void Update()
         {
         IsOpenCheck = InstructionButton.GetComponent<popUpInstOpen1>();//this line accesses script on open button
         Debug.Log(IsOpenCheck.IsOpen);
         if (gvrStatus)
         {
             gvrTimer += Time.deltaTime;
             gazeCircle.fillAmount = gvrTimer / totalTime;
             
         }
         
         if (gvrTimer > totalTime)
         {
             
             gazeCircle.fillAmount = 0;
             Destroy(InstructionPanel);
             InstructionPanel.SetActive(false);
             if (IsOpenCheck.IsOpen = true)
             {
                 InstructionPanel.SetActive(false);
                 Debug.Log("instructions close line 41");
                 IsOpenCheck.IsOpen = false;
                 Debug.Log(IsOpenCheck.IsOpen);
             }
             else
             {
                 //keeps panel open
                 Debug.Log(IsOpenCheck.IsOpen);
                 InstructionPanel.SetActive(true);
                 Debug.Log("instructions panel stay open line 50");
             }
         }
     }
 
     public void OnPointerEnter()
     {
             gvrStatus = true;
     }
 
     public void OnPointerExit()
     {
         gvrStatus = false;
         gvrTimer = 0;
         gazeCircle.fillAmount = 0;
         Debug.Log("instructions onpointer exit gvr true line 66 popupInstClose1");
     }
 }
 
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
1
Best Answer

Answer by HellsHand · Mar 25, 2021 at 08:13 PM

Line 38 of your close script, always evaluates to true, unless I missed something you should be using '==' instead of '='.

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 kayakmtb · Sep 07, 2021 at 10:40 AM 0
Share

Thanks, for the pointer that made a difference!

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

114 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

Related Questions

simple networked int script simply dont work. 1 Answer

Add force when button is pressed 2 Answers

having trouble adding a button to end session 2 Answers

How to overlap 2 or more UI Elements 1 Answer

How do I attach buttons to object (3d plane) ? 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