Alter variables in other Game Objects

I have a script to reference one of several arrays and apply the values to a number of variables in a number of Game Objects. I need to know how to reference and change variables from other Game Objects.

using UnityEngine;
using System.Collections;

public class MathVariables : MonoBehaviour {
	string[] Eq1 = {"3","x","2","8","3","x","6","","","","","","subtract","2","divide","3","","3x+2=8","3x=6","x=3"};
	public GameObject LeftText;
	public GameObject RightText;
	public GameObject TopText;
	public GameObject BottomText;

	// Use this for initialization
	void Start () {
		newEquation();
	}
	
	// Update is called once per frame
	void Update () {

		}


	void newEquation () {
		LeftText.Ringvariable = Eq1[0];
		RightText.Ringvariable = Eq1[1];
		TopText.Ringvariable = Eq1[2];
		BottomText.Ringvariable = Eq1[3];
	}
}

1 Answer

1

LeftText.GetComponent().publicvariable = value;

that is how you can modify data in other game objects. You can also call a function from the other class you modify the value if you do not want to make the value public.

Fantastic. THat worked. Thank you.