RgClube
1
Hello everyone, I have a problem with accessing Vector2 from another script, it is always 0, but in the script from which I refer to it everything works like clockwork. What can I be doing wrong? Here is code:
Reference to Vector2:
public GameObject player;
Vector 3 targetPos;
targetPos = player.GetComponent<PlayerMovement>().playerPosVector;
PlayerMovement script:
public Vector2 playerPosVector;
void Update()
{
playerPosVector = playerPos.transform.position;
}
I figured it out myself. All that is needed for the correct link to a script on another game object is FindObjectOfType. Changed my script to:
PlayerMovement playerMovement;
playerMovement = FindObjectOfType();