hurnhu
1
so ive looked at many different questions about this so far… im trying to access the varible “height” from the script “testing” on a cube. from the script vault. they are both in c# here is the testing script `sing UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections;
public class testing : MonoBehaviour {
public static int height = 2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
alright that want to had, now here is the vault script where im trying to access the int height `using UnityEngine;
using System.Collections;
public class vault : MonoBehaviour {
// Use this for initialization
private GameObject test;
private int num = 0;
void Start () {
}
// Update is called once per frame
void Update () {
test = GameObject.Find("Cube");
num = testing.height;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 1)) {
print (num);
}
}
}
`
i fixed the code above, now it works and does return the right value!!!
again thanks for the help!
testing
public class testing : MonoBehaviour{
public int height = 2;
}
vault
public class vault : MonoBehaviour{
private GameObject test;
private int num = 0;
void Start () {
test = GameObject.Find("Cube");
num = test.GetComponent<testing>();
print(""+num.height)
}
}
Note that GameObject.Find will find by name, but GameObject.FindWithTag by tag.