- Home /
Question by
quieresss · Jul 30, 2021 at 07:52 PM ·
uicanvasrecttransform
stopping an ui element from moving if the y axis value is too low
here's the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Options : MonoBehaviour
{
RectTransform canvas;
RectTransform button;
Vector3 startingPosition;
public float speed;
public static bool yees;
public GameObject canvaes;
void Start()
{
button = gameObject.GetComponent<RectTransform>();
canvas = GameObject.Find("Canvas").GetComponent<RectTransform>();
startingPosition = transform.position;
speed = -5f;
}
public void OnPressed()
{
yees = true;
}
void Update ()
{
if(yees)
canvaes.transform.Translate(0f, speed, 0f);
}}
basically what it does is it makes an ui element move endlessly downwards if the OnPressed function is activated. what i want it to do is to stop at a certain point on the y axis. i'm kind of confused as to how the RectTransform works, so i would be thankful if someone could tell me which value i should check for to acomplish this goal.
Comment