text wont stop scrolling upwards?

trying to make a credits scene where the text scrolls up and then stops at a certain position but no matter what i do it wont stop. heres the code:

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

public class creditscroll : MonoBehaviour {

    public Text haha;
    Vector3 angr;

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {

        angr = new Vector3(haha.transform.position.x, haha.transform.position.y, 0);

        //haha.transform.Translate(0, 0.01f, 0);
        angr.y += 0.05f;
       
        haha.transform.position = angr;

        angr.y = Mathf.Clamp(angr.y, -600, 190);
    }
}

Swap lines 24 and 26 so you clamp the Y value of the position before you set the text to use that position.

thanks for the advice, shame to say it didnt work. :frowning:

Are you sure the values “-600” and “190” are correct?

If you start at -600 and count up to 190, that’s 790 total units the text has to move. Moving 0.05 at 60 frames per second means you move 3 units a second. 790 units at 3 units a second will take ~260 seconds to scroll the full amount.

I suggest testing with really small values like 0 to 1 or 0 to 10 just to see that it works before you try to find the values you actually want.

oh my gosh youre right, haha! i forgot i was setting min and max values, thought i was setting x and y values, thank you, i’ll try this right away!

edit: now that thats solved i have one last issue, i need to clamp the position as demonstrated below, but visual studio is telling me that on line 23, cannot implicitly convert type float to unityengine.vector3, any suggestions what to try?

public class creditscroll : MonoBehaviour {

    public Text haha;
    Vector3 angr;

    // Use this for initialization
    void Start () {
      
    }
  
    // Update is called once per frame
    void Update () {

        angr = new Vector3(haha.transform.position.x, haha.transform.position.y, 0);

        //haha.transform.Translate(0, 0.01f, 0);
      
        //angr.y += 0.01f;

        //angr.y = Mathf.Clamp(angr.y, 0, 5);

        haha.transform.Translate(0, 0.1f, 0);
        haha.transform.position = Mathf.Clamp(angr.y, -535, 190);
      
    }
}

Yeah, transform.position is a Vector3 with x/y/z coordinates, so you have to give it 3 values for x, y, and z. Since you only want to move the Y axis, you can assign x and z to the values they already have.

change line 23 to this:

haha.transform.position = new Vector3(haha.transform.position.x, Mathf.Clamp(angr.y, -535, 190, haha.transform.position.z);