in GetComponent
I found this thread in 3 hours searching through all Q/A about accessing the variable in other scripts
it will not only help new players it’ll help me too as I’ll propably forgot about it and want to search for it in future
and please don’t say to people on most frequently asked questions to RTFM because maybe the man doesn’t describe that problem correctly
if someone has better example of code please share it to help our wiki
please add the code
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public OtherScript sscript;
public GameObject ObjectWithScript;
void Start() {
sscript someScript;
ObjectWithScript = GameObject.Find("Player");
sscript = ObjectWithScript.GetComponent("OtherScript") as OtherScript;
}
void Example() {
Debug.Log (OtherScript.x);
}
}
using UnityEngine;
using System.Collections;
public class OtherScript : MonoBehaviour {
public int x = 10;