Hello dear community! I am stuck with a silly problem. How do you get the position of an object from the other script? The problem, as I understand it - the line of code needed, can only be called from an Update block and therefore cannot be accessed from the other script. Can you help me please?
In my case: I want a rocket to spawn not in the middle of the screen, but inside the character. For this reason, I assume I need to know where the character in space is positioned.
My script so far:
//move.js
function Start()
{
}
function Update()
{
var playertrans = this.transform.position.x;
var playertransy = this.transform.position.y;
//Here, inside Update scope {Debug.Log(playertrans) works pefectly};
// the rest of the movement script
}
//shooting.js
var script : move;
script = GetComponent("move");
function Update(){
Debug.Log(script.playertrans);
// Here Debug.Log(script.playertrans) returns null as if it doesn't have the access to the block of code containing the value
// the rest of the shooting script
}