I have a game object that creates a keyboard in side of my world canvas. I am working out the offset positions for each key, and appear to be doing that correctly. However, when I set the positions in the actual keys, the values are being offset by anything from 100 - 1000.
This is the basic method I am currently using to set the position:
public void SetDimensions(Vector2 position)
{
GetComponent<RectTransform>().localPosition = position;
Debug.Log(key + ": " + position);
}
I have also tried using .position
and .anchoredPosition
, as per the somewhat confusing API reference. I have also tried simply referencing transform.localPosition
and transform.position
. No matter what, the output is exactly the same. The debug output confirms that I am working out the correct local position, but no matter what I do, that is not the value being set to my transform.
As you can see, I have my pivot set to the center; though I think this may have an impact, it certainly should not cause an offset of 400-500.
As per request, this is my main canvas:
What am I doing wrong, or more specifically, how do I set the exact local position of a game object using a RectTransform
?