[2D] Getting the y coordinate of the top of a game object
I'm working on some ladder-climbing functionality, and I need to get the y coordinates of the top of the player and the ladder they're trying to climb. I thought I could get the y coordinate of the top of a sprite game object like so:
transform.position.y + (spriteRenderer.bounds.size.y / 2)
But apparently, that's not quite right. Despite the player clearly being above the ladder, the ladder's top edge value (as calculated by the above algorithm) is higher than that of the player's.
So, how do I go about it? I'm using Unity 5.6.2f1
Your answer
Follow this Question
Related Questions
Unity2D C# Randomly Spawn GameObject in an Area over another GameObject 1 Answer
Scale of object does not update properly with public variable 1 Answer
how to make the sprite invinsible and reappear and how to call the sprite data from another script 0 Answers
C# 2D Top down game how to detect if objects are touching while they can pass through each other? 1 Answer
GetSpectrumData Why last element in array allways is zero? 0 Answers