So what I’m trying to do is call a function from another script.
public class Manager
{
// Use this for initialization
void Start()
{
SetPlayerPosition();
}
}
okay that’s the Manager Sample , here the other
public class Player : MonoBehaviour
{
// Use this to set Player Position
public void SetPlayerPosition()
{
transform.position = new Vector3(150, 0, 5);
}
}
I know this might be a simple question but this is bugging me since Ive done it before, I might even answer this myself after further research but just to post in case someone has same problem in future.
Note: The error is on the Manager.cs “The name ‘SetPlayerPosition’ does not exist in the current context”
You need to create a reference to a specific instance of the Player script (i.e. to the game object it is attached to). The multiple ways to do this are covered here:
Accessing Other GameObjects
Then you will use a variable pointing to that instance of the script to make the access. Something like:
playerScript.SetPlayerPosition();
I tried this and it worked thanks for your help.
void Start()
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
player.GetComponent<Player>().SetPlayerPosition();
}