Problem with UI

i have problem with the UI
when i click to make it follow the cursor it follow it but if i add an offset it broke i try with localpos, global pos , achoredPosition ,
i add the offset based on distance, but if i add it as a var it work
controled in the inspector .
with global pos … lastly forgive me for my broke English I’m not native speech language

I apologize, but I’m not entirely sure what you’re meaning… we’re not adding an offset to any UI in this lecture. I do want to help. Are you sure it’s this lecture you’re referring to?

it’s not about this lecture … sorry again for my broken English … I have problem with scroll Rect Massive impact on performance i try to mack it with out scroll rect… so i try to write a code

using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
public class scrolRectT : MonoBehaviour
{
    [SerializeField] private RectTransform _rectTransform;
    [SerializeField] private float _minY, _maxY;
    [Range(0,1)]
    [SerializeField] private float _speedLimt = 1;
    [SerializeField] private float _moveTimerRest = 1;
    [SerializeField] private float _smothTransion = 5;
    [SerializeField] private float _resetClampSmoth = 10;
    //[SerializeField] private float _offset;
    private Camera _camera;
    private bool IsClick;

    private Vector3 _Dir;

    private Vector2 _Pos;
   
    private Vector3 _WoldPoint;
    private Vector3 _startPos;
    private float _MoveSpeed = 2;



    private float _speedTimer;
    private bool _oneClick = false;
    private float _distance;

    private float _movingTimer;
    private float _dis;

    private float _navgSpeed;

    private float _screenHight;

    private bool OneCall = true;

    private bool _slideMovement = false;    

    private void Awake()
    {
        _rectTransform = GetComponent<RectTransform>();
    }
    private void Start()
    {
        _camera = Camera.main;
        
    }



    void Update()
    {

        if (OneCall)
        {
            _maxY = _rectTransform.rect.height - (Screen.height * 2);
            _screenHight = Screen.height;
        }

        _Pos = gg._Pos;
        IsClick = gg.IsClick;

        //Debug.Log(_Pos);
        Vector3 pos = _rectTransform.localPosition;
        




        if (IsClick)
        {            
            if(_oneClick)
            {
                _startPos = _camera.ScreenToWorldPoint(_Pos);
                _oneClick = false;

            }
            _speedTimer += Time.deltaTime;
           //Vector3 offset = _camera.WorldToScreenPoint(transform.position) - (Vector3)_Pos;

            _WoldPoint = _camera.ScreenToWorldPoint(_Pos);
           
            _WoldPoint.x = 0;
            _WoldPoint.z = 0;
            _Dir = (_WoldPoint - _startPos).normalized;
            _Dir.x = 0;
            _Dir.z = 0;
            _movingTimer = _moveTimerRest;
            _distance = Vector3.Distance(_WoldPoint,_startPos);    
          
          
            Vector3 offset = _WoldPoint - transform.position;

            offset.z = 0;

            transform.position = _WoldPoint + offset;
            
          
      




        }
        else
        {
            if (_movingTimer > 0)
            {
                _navgSpeed = _distance / _speedTimer;
                _speedTimer = 0;
                _navgSpeed = Mathf.Clamp(_navgSpeed, 0.0f, 100.0f);
                _navgSpeed *= _speedLimt;
                _dis= _distance * _navgSpeed;

                
              
               

            }
            else
            {
                // _Dir = Vector3.zero;
                _navgSpeed = Mathf.Lerp(_navgSpeed, 0, Time.deltaTime * _smothTransion);
            }
            pos = (_Dir * _navgSpeed) + _rectTransform.localPosition;
            _movingTimer -= Time.deltaTime;
            _oneClick = true;
           // Debug.Log(_navgSpeed);
        }



        if (_navgSpeed <= 0.3f || pos.y > _maxY + 500|| pos.y < _minY - 500)
        {
            _navgSpeed = 0;
            pos.y = Mathf.Clamp(pos.y, Mathf.Lerp(_rectTransform.localPosition.y, _minY, _resetClampSmoth * Time.deltaTime), Mathf.Lerp(_rectTransform.localPosition.y, _maxY, _resetClampSmoth * Time.deltaTime));
        }
        _rectTransform.localPosition = pos;

        
    }

Which course is this related to?

I think what you’re trying to do is implement a custom scroll rect (what is wrong with the UI ScrollRect). I don’t have time tonight to go through this, I’ll take a look tomorrow after work.

try to add more then 5 element with button and text you will have drop
frame about 70 80 per

i try to make it with scroll rect i make the text dynamic with scriptable Object
i use physics engine to set active only 3 element of text button object and stil stutter can you
imagen how trash is scrollRect is

Once again, which course is this related to?

i’m not relating to any course this is very small project to me just i ask .
dos you not answer the question if it out of any course !!
i’m just ask for help …

I try my best. I have to prioritize problems related to the courses I’m a TA for. My initial confusion was because this post was tied to a specific lecture in the Turn Based Strategy Course.

I’ll try to work through this tomorrow. You might also try asking for help in our Discord.

I’ll do what I can, I can’t make any guarantees.

So it looks like what you’re trying to do is make a custom Scroll Rect from scratch (once again, why not a Unity Scroll Rect, you won’t beat it’s performance if you try).

A couple things don’t compute, and I suspect I don’t have all the information… for example,

I can’t find a reference to gg anywhere else in the script, so I have absolutely no idea what this is… I’m also not seeing anywhere OneCall is used except in that first part of Update(), it’s set nowhere else in the script and it’s private, so it basically reads if(true) rather than if(OneCall).

In terms of the scroll functions itself, it “looks” like it will scroll, but it also looks overly complex, mostly to allow a smooth offset. I’m also not sure it wlll show only what is “visible” within a Rect like the Unity Scroll Rect (which was designed for this purpose) would do.

So are you saying that the issue with the built in Scroll Rect is that it bogs down when there are just a few items in it? Without knowing more about what those items are, I suspect the issue isn’t with the Scrolll Rect, but with the items you’re putting within the Scroll Rect. Do you have scripts within that have large Update() loops?

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms