Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Play Animation Backwards Issue

Discussion in 'Animation' started by Scoutron, Oct 24, 2014.

  1. Scoutron

    Scoutron

    Joined:
    Jul 15, 2014
    Posts:
    3
    I have two scripts for two pieces of 3D text. When you click play, the camera rotates over to another piece of 3D text, and if you click back it plays that same animation, but backwards. This is the code for the back button, which when clicked, plays the animation by teleporting the camera instantly to 0 degrees, and rotates it over to the back button again.

    Code (JavaScript):
    1. var Cam : GameObject;
    2. Cam = GameObject.Find("Main Camera");
    3.  
    4.  
    5. function Start () {
    6. renderer.material.color = Color.blue;
    7. }
    8.  
    9. function OnMouseEnter () {
    10. renderer.material.color = Color.red;
    11. }
    12.  
    13. function OnMouseOver () {
    14. if(Input.GetMouseButtonUp(0)) {
    15. animation["CameraRotate"].layer=10;
    16. animation["CameraRotate"].wrapMode = WrapMode.Once;
    17. animation["CameraRotate"].speed=-1;
    18. animation["CameraRotate"].time = animation["pCameraRotate"].length;
    19. animation.CrossFade("CameraRotate");
    20. Cam.animation.Play();
    21.     }
    22. }
    23.  
    24. function OnMouseExit () {
    25. renderer.material.color = Color.blue;
    26. }