Skip to main content

If both scipts ar eonscripts are on the same GameObjectGameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed"speed.


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speedspeed.

Note : You need to replace "nameOfObjectYourScriptIsOn"nameOfObjectYourScriptIsOn with the name of the GameObjectGameObject you have attached movethe move script to.

If both scipts ar eon the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed".


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace "nameOfObjectYourScriptIsOn" with the name of the GameObject you have attached move script to.

If both scripts are on the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case speed.


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace nameOfObjectYourScriptIsOn with the name of the GameObject you have attached the move script to.

If both scipts ar eon the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed".


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace "nameOfObjectYourScriptIsOn" with the banename of the GameObject you have attached move script to.


Not sure if this actually works though since I can't test it atm, but I think this is how it works.

If both scipts ar eon the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed".


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace "nameOfObjectYourScriptIsOn" with the bane of the GameObject you have attached move script to.


Not sure if this actually works though since I can't test it atm, but I think this is how it works.

If both scipts ar eon the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed".


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace "nameOfObjectYourScriptIsOn" with the name of the GameObject you have attached move script to.

Source Link
BiiX
  • 499
  • 1
  • 7
  • 26

If both scipts ar eon the same GameObject, you can use this

gameObject.GetComponent<move>().speed

This will access the given variable, in this case "speed".


If the scripts are on different GameObjects you can do this :

GameObject.Find("nameOfObjectYourScriptIsOn").GetComponent<move>().speed

and you should have access to the variable speed.

Note : You need to replace "nameOfObjectYourScriptIsOn" with the bane of the GameObject you have attached move script to.


Not sure if this actually works though since I can't test it atm, but I think this is how it works.