Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 gowtham_innovreality · Oct 14, 2015 at 09:54 AM · animationgameobjectbuttonhow toreverse

Can we do Animation for Game objects (child or parent) using control on Buttons like Play, Pause, Reverse or Forward in Unity 5 by C# script ?

@gowtham_innvoreality

Hi I want to animate my Game objects that may be child or parent where by using button animation are controlled just like we use to watch video in player same function like Play, Pause, Reverse & Forward like that.

I was able to animate my Game object til Play, Pause & Forward animation on Game objects. But not possible on Reverse of animation.

My code below:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class cubeanima : MonoBehaviour { // Cube Parent as Game object

 public GameObject Cubeanim; // Cube Parent
 public Canvas myCanvas; // Canvas with Button as game object


 // Use this for initialization

 public void Start ()
 {

     Debug.Log ("Game Object Activated");
     Cubeanim.SetActive (true); // Cube parent is activated
     myCanvas.gameObject.SetActive(true); // Canavas is active

 }


 // Pause & Resume Gameobject during Game play

 public void Pause_Anim() 
 {

     Debug.Log ("Pressed Pause");

     if (Time.timeScale == 0.25F) 
     {
         Time.timeScale = 0F;

     } 
     else 
     {
         Cubeanim.SetActive (true);
         myCanvas.gameObject.SetActive (true);
         Cubeanim.GetComponent<Animator> ().enabled = true;
         Time.timeScale = 0.25F;

     }

 }




 // Repositoning Cube to original position

 public void Rewind()
 {

     Debug.Log ("Pressed Repos");

     //Unhiding all button which are game objects

     Cubeanim.SetActive (false);




 }


 // Fastforward Cube movement

 public void Forward()
 {


     Debug.Log ("Pressed Forward");
     Cubeanim.GetComponent<Animator> ().enabled = true;

     if (Time.timeScale == 0.25F) 
     {
         Time.timeScale = 1.5F;

     } 
     else 
     {
         Time.timeScale = 0.25F;
     }
 
 }


      

}

In the above Rewind(). i have made the Game object to false instead i want game object to be true & display reverse play of Animation.

i have Animation clip of "Cmove" for my Gameobject.

Please help me on reverse. Any suggestion or advice on code are welcome.

Please tell any solution only on C#. I don't know Javascript in Unity.

Thank you.

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 f-Schmitz · Oct 14, 2015 at 01:27 PM

you can set the animation["animationName"].speed to -1. Then the animation should play backwards. For that you need the animation Component of your Cubeanim.

When you want to play the animation normal again. Just set the speed back to 1.

Comment
Add comment · Show 6 · 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 gowtham_innovreality · Oct 15, 2015 at 06:04 AM 0
Share

hi @f Schmitz So forward play i need to set speed to +1 & for reverse i need to set -1 !

avatar image gowtham_innovreality · Oct 15, 2015 at 09:57 AM 0
Share

hi @f Schmitz i'm getting error while compiling called speed not found. Whats the reason of error ?

avatar image meat5000 ♦ gowtham_innovreality · Oct 15, 2015 at 09:58 AM 0
Share

Dont post comments as asnwers. Use the 'Add Comment' link or the little Reply arrow (This isnt immediately obvious, right of the username).

avatar image gowtham_innovreality meat5000 ♦ · Oct 16, 2015 at 05:04 AM 0
Share

@meat5000

Thanks for an information.

Do you have any idea on an issue above on discussion? You are welcome Thanks

avatar image f-Schmitz gowtham_innovreality · Oct 16, 2015 at 08:02 AM 0
Share

Are you trying to use the command on the GameObject?

for your code you need something like:

      public Animation CubeAnim; // The animation component of your GameObject
 
      public void Rewind()
      {
          [... your code...]
          CubeAnim["AnimationName"].speed = -1.0f; // AnimationName is the name of the actual animation
      }

It compiles for me. How have you implemented it?

Also Time.timeScale slowsdown/fastforwards your entire game, not just the animation.

avatar image gowtham_innovreality f-Schmitz · Oct 19, 2015 at 07:27 AM 0
Share

@ f Schmitz

So inorder to achieve animation of forward & reverse, how can we do? By not using Time.timescale.

do I need to create different clip or single animation clip is enough ?

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

GameObject as a toggle button to play character Animation 1 Answer

Help touch button 1 Answer

Button animation state stays Pressed or Highlighted after disabling GameObject 0 Answers

Two Animations With One Button Press 1 Answer

Animator.Update High CPU Usage on Unity 5 resulting in bugs on Android 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