Search Unity

Question 2D animation no longer working - Need Help

Discussion in 'Animation' started by praisejourney, Nov 23, 2022.

  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.