Question by
Eudauminiac · May 31, 2020 at 08:00 PM ·
transform.positionother script
Transfrom is different if called from another script
Hi guys
Hopefully you can help me, as I am pulling out my hair because of this.
I have a GameObject called Player, and on that is a script called PlayerController. In this script I have the following method:
public Vector2 GetPlayerPosition(string caller)
{
Debug.Log(caller + ":" + GetComponent<Transform>().position.x + "," + GetComponent<Transform>().position.y);
Vector2 tmp = new Vector2(GetComponent<Transform>().position.x, GetComponent<Transform>().position.y);
return tmp;
}
When I call this from the PlayerController-script, it returns the correct value for the x and y - like (-1,2) However, when I call it from another script, which has the following reference:
[SerializeField] PlayerController player;
Using the following method call:
player.GetPlayerPosition("enemy");
it always logs (0,0).
So I end up with something like:
player:-0,4298997,0,8567935
enemy:0,0
Do you guys have any idea why this is happening. I really am at a loss here...
Comment