c# - Unity3D - Move UI object to center of screen while maintaining its parenting -


i have ui image parented recttransform container, parented ui panel, parented canvas.

i want able move ui image center of screen (ie. canvas) while leaving parenting hierarchy. goal animate ui image center now. can please let me know code like?

enter image description here

to answer original question, can place uicell @ center of screen using:

private recttransform rect;  void start()  {     rect = getcomponent<recttransform>();     rect.position = camera.main.screentoworldpoint(new vector3(screen.width / 2, screen.height / 2, 10)); } 

there several ways move cell desired destination. 1 method use vector2.lerp. however, due nature of rectangular transform parental hierarchy, things little complicated positioning - below example of how could accomplish movement.

float t;  void update() {     t += time.deltatime;     rect.localposition = vector2.lerp(rect.localposition, new vector2(0, 0), t/3f); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -