(C#)Referencing Variable from a script attached to a prefab in the scene

Hey there.

Basically, we have prefab in the scene ‘FPSController’, with a script named ‘PlayerFlightController’, and a public integer in there named ‘Speed’.

A second script attached to a different game object needs to reference ‘Speed’.
Probably barking up the wrong tree, but this is what I tried so far-

	public int Speed;
	void Start()
	{
	GameObject Player = GameObject.Find("FPSController");
	Player.PlayerFlightController = Player.GetComponent<PlayerFlightController> ();
	Speed = FPSController.gameObject.GetComponent<PlayerFlightController> ();

Any ideas?

Firstly, make speed a static variable.

I use something similar in one of my projects.

I have a script named LivesManager and in that script is a static variable called Lives.

Then from my other scripts I access that variable with LivesManager.Lives

if(collider.gameObject.name == "Player")
		{
			LivesManager.lives += livesValue; // Decrease Player Lives total
		}

So in your case it would be PlayerFlightController.Speed //Do your stuff here

or something like that.

:slight_smile: