I am just starting out with Unity and have a question about making a script public. I have the following code:
using UnityEngine;
using System.Collections;
public class CoinRandomizer : MonoBehaviour {
public Transform[] spawnlocations;
public GameObject[] whatToSpawnPrefab;
public GameObject[] whatToSpawnClone;
void Start()
{
makingCoins ();
}
void makingCoins(){
whatToSpawnClone [0] = Instantiate (whatToSpawnPrefab [0], spawnlocations [0].transform.position, Quaternion.Euler (0, 0, 0)) as GameObject;
whatToSpawnClone [0] = Instantiate (whatToSpawnPrefab [0], spawnlocations [0].transform.position, Quaternion.Euler (0, 0, 0)) as GameObject;
whatToSpawnClone [0] = Instantiate (whatToSpawnPrefab [0], spawnlocations [0].transform.position, Quaternion.Euler (0, 0, 0)) as GameObject;
}
}
…I have set up another script dictating when this script should run (the other script runs when your player object makes contact with a coin, so this script runs to generate the next coin, see script in comments), but I need to make “makingCoins” a public variable for the other script to call / access.
Simply adding “public makingCoins” to the top of the code doesn’t work. Help!