Hello everybody
I’m trying to making a system to move smoothly the panel to the up when a new message is add to it ( Like messenger app )
For this I use these line of code on the panel wich contain message element:
float valutoadd = lastbutton.GetComponent<RectTransform>().rect.height / 2;
float distance = Mathf.Abs(minposTR.position.y - (lastbutton.position.y - valutoadd));
if ((lastbutton.position.y - valutoadd) > minposTR.position.y)
{
up = false;
}
transform.position += Vector3.up * Time.deltaTime * (speed * distance);
Debug.Log(" valu to add" + valutoadd + "// Distance:" + distance + " POS lastbutton:" + (lastbutton.position.y - valutoadd) + " Minpostr pos:" + minposTR.position.y);
The weirdest part comes here… When I add the value "valutoadd " , the final position of my panel is wrong…
If I remove "valutoadd " to all line of code , the position of the panel is good.
I Post here some screenshot for more details :
In this first screen ( MinPos in red) , I removed valutoadd , corresponding to the height /2 of the message element.
And it’s work perfectly at this point, the center of the message align to the MinPos Y.
But I need to the panel to move up to have the bottom of the message element align to the MinPos
That’s why I calculate :
float valutoadd = lastbutton.GetComponent<RectTransform>().rect.height / 2;
So if I add it to my code like above, this is what I have :
You can see that MinPos and the bottom of the Message element are not align at all…
And I don’t understand what i’m doing wrong here …
When i’m getting the height/2, I take the white image background height , not the Text height.
If someone can explain me how to resolve that you will litteraly save my day ^^’ ( 10hours of debbuging and no solution here for me…)
Have a good day ! :)!