• 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 BrandonYJ · Jan 05, 2017 at 06:04 PM · mouseoverfillfillrate

how to Reverse VR gaze fill image HandleOut exit?

I'm using VR sample button input for the image fill but what i'm trying to achieve is after on handle out the fill bar reverse back to 0 with animation instead of resetting to 0 immediately without animation. Any help on making it possible will do I'm kinda new to Unity As well. Cheers for the help

     public IEnumerator WaitForBarToFill ()
     {
         // If the bar should disappear when it's filled, it needs to be visible now.
         if (m_BarCanvas && m_DisappearOnBarFill)
             m_BarCanvas.SetActive(true);

         // Currently the bar is unfilled.
         m_BarFilled = false;

         // Reset the timer and set the slider value as such.
         m_Timer = 0f;
         SetSliderValue (0f);

         // Keep coming back each frame until the bar is filled.
         while (!m_BarFilled)
         {
             yield return null;
         }

         // If the bar should disappear once it's filled, turn it off.
         if (m_BarCanvas && m_DisappearOnBarFill)
             m_BarCanvas.SetActive(false);
     }


     private IEnumerator FillBar ()
     {
         // When the bar starts to fill, reset the timer.
         m_Timer = 0f;

         // The amount of time it takes to fill is either the duration set in the inspector, or the duration of the radial.
         float fillTime = m_SelectionRadial != null ? m_SelectionRadial.SelectionDuration : m_Duration;

         // Until the timer is greater than the fill time...
         while (m_Timer < fillTime)
         {
             // ... add to the timer the difference between frames.
             m_Timer += Time.deltaTime;

             // Set the value of the slider or the UV based on the normalised time.
             SetSliderValue(m_Timer / fillTime);
             
             // Wait until next frame.
             yield return null;

             // If the user is still looking at the bar, go on to the next iteration of the loop.
             if (m_GazeOver)
                 continue;

             // If the user is no longer looking at the bar, reset the timer and bar and leave the function.
             m_Timer = 0f;
             SetSliderValue (0f);
             yield break;
         }

         // If the loop has finished the bar is now full.
         m_BarFilled = true;

         // If anything has subscribed to OnBarFilled call it now.
         if (OnBarFilled != null)
             OnBarFilled ();

         // Play the clip for when the bar is filled.
         m_Audio.clip = m_OnFilledClip;
         m_Audio.Play();

         // Wait for the screen to fade out.
         StartCoroutine (FadeToMenu ());

         // If the bar should be disabled once it is filled, do so now.
         if (m_DisableOnBarFill)
             enabled = false;
     }
     private IEnumerator FadeToMenu ()
     {
         // Wait for the screen to fade out.
         yield return StartCoroutine (m_VRCameraFade.BeginFadeOut (true));

         // Load the main menu by itself.
         Application.LoadLevel ("exterior");
     }

     private void SetSliderValue (float sliderValue)
     {
         // If there is a slider component set it's value to the given slider value.
         if (m_Slider)
             m_Slider.value = sliderValue;

         // If there is a renderer set the shader's property to the given slider value.
         if(m_Renderer)
             m_Renderer.sharedMaterial.SetFloat (k_SliderMaterialPropertyName, sliderValue);
     }


     private void HandleDown ()
     {
         // If the user is looking at the bar start the FillBar coroutine and store a reference to it.
         if (m_GazeOver)
             m_FillBarRoutine = StartCoroutine(FillBar());
         m_Timer = 2f;
     }


     private void HandleUp ()
     {
         // If the coroutine has been started (and thus we have a reference to it) stop it.
         if(m_FillBarRoutine != null)
             StopCoroutine (m_FillBarRoutine);

         // Reset the timer and bar values.
         m_Timer = 0f;
         SetSliderValue(0f);
     }


     private void HandleOver ()
     {
         // The user is now looking at the bar.
         m_GazeOver = true;

         // Play the clip appropriate for when the user starts looking at the bar.
         m_Audio.clip = m_OnOverClip;
         m_Audio.Play();
         //m_text.SetActive(true);

         m_FillBarRoutine = StartCoroutine(FillBar());
         //HandleDown(); // Here autoclick
     }


     private void HandleOut ()
     {
         // The user is no longer looking at the bar.
         m_GazeOver = false;
         //m_text.SetActive(false);
         // If the coroutine has been started (and thus we have a reference to it) stop it.
         if (m_FillBarRoutine != null)
             StopCoroutine(m_FillBarRoutine);

         // Reset the timer and bar values.
         m_Timer = 0f;
         SetSliderValue(0f);
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Filling array with gameObjects 2 Answers

What is the best way to evenly distribute objects to fill a curved space? 1 Answer

OnMouseOver GUI not appearing 1 Answer

detect mouse over object in the scene 1 Answer

Help With OnMouseOver and object Selection 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges