Is it possible to get the value of the variable from script B to script A? I want to print the remaining enemies on the scene using OnGUI() but my raycast and GameObject[] enemies is in another script.
Here’s my code:
public class Damage: MonoBehaviour
GameObject[] enemies;
enemies = GameObject.FindGameObjectsWithTag ("enemy") as GameObject[];
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 50f)){
GameObject g = hit.collider.gameObject;
if (Vector3.Distance (transform.position, g.transform.position) < 10){
Destroy(g);
}
}
Here's the other script: public class GameStart: MonoBehaviour public GameObject player; public bool startGame, _player; public void Start(){ Instantiate(player, transform.position, transform.rotation); } void OnGUI(){ if (!startGame){ GUI.Box(new Rect(mmPosX, mmPosY, 150, 150), "Main Menu Controls: W/S - forward/backward A/D - rotate left/right SPACE - bomb"); if (GUI.Button(new Rect(sPosX, sPosY, 100, 30), "Start")){ startGame = true; } } else{ GUI.Label(new Rect(10, 10, 100, 30), "Enemies Left: " + enemies.length); //call 'enemies' variable from 'Damage' script } }