Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question 2D animation no longer working - Need Help

Discussion in 'Animation' started by praisejourney, Nov 23, 2022 at 6:08 AM.

  1. praisejourney

    praisejourney

    Joined:
    Sep 4, 2022
    Posts:
    1
    I am updating a 2D game that I wrote in 2017. I noticed that when I upgraded to the 2021 version my animations go super fast. Can you tell what I need to do to upgrade my 2D C# animation script. Thank you so much!

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5.  
    6. public class CloudAnime : MonoBehaviour {
    7.  
    8.     public Image imgCloud;
    9.     public Image imgStart;
    10.     public Image imgEnd;
    11.  
    12.     public float cloudspeed = 3;
    13.  
    14.     private float sw;
    15.  
    16.     void Start () {
    17.         sw = Screen.width;
    18.         Debug.Log (sw);
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update () {
    23.  
    24.     //    RectTransform rt = imgCloud.rectTransform;
    25.     //    imgCloudWidth = rt.rect.width;
    26.  
    27.         Vector3 pos = imgCloud.transform.position;
    28.         Vector3 startPos = imgStart.transform.position;
    29.         Vector3 endPos = imgEnd.transform.position;
    30.  
    31.         if (pos.x < endPos.x) {      
    32.             Vector3 setThis = new Vector3 (startPos.x, imgCloud.transform.position.y);  
    33.             imgCloud.transform.position = setThis;
    34.         }
    35.             else
    36.         {
    37.             pos.x -= cloudspeed;
    38.             imgCloud.transform.position = pos;
    39.         }
    40.  
    41.     }
    42. }
    43.  
     
unityunity