Hi,
Another Nubee here, I am getting on great creating a game but I am stuck with a bit of scripting,
can anyone Help please,
Ok I have lets say 5 game objects with the following script attached but deactivated
public class Renderer : MonoBehaviour
{
public UnityEngine.Renderer rend;
void Start()
{
rend = GetComponent<UnityEngine.Renderer>();
rend.enabled = true;
}
{
bool oddeven = Mathf.FloorToInt(Time.time) % 2 == 0;
rend.enabled = oddeven;
}
}
This works perfectly with game object when activated and makes the object appear to flash on and off.
However
I have disabled the script in each object and as expected the Game objects now are static and not flashing.
Now I want to make 1 game object flash by enabling the above script randomly between the 5 objects.
All my game objects are in the Hierarchy as is the following Array Script.
{
public GameObject[ ] BoxArray;
public int startWait;
public float spawnWait;
float startwait;
int randBoxArray;
public bool stop;
public AudioSource Ding;
// Start is called before the first frame update
void Start()
{
StartCoroutine(WaitBoxArray());
}
void Update()
{
}
IEnumerator WaitBoxArray()
{
yield return new WaitForSeconds(startwait);
while (!stop)
{
randBoxArray = Random.Range(0, 5);
Instantiate(BoxArray[randBoxArray]);
yield return new WaitForSeconds(spawnWait);
}
}
}
the array script works perfectly to instantiate a game object
here is the problem I have created a script and added it to 5 empty game objects then added them to the array
{
public GameObject Cube;
void Start()
{
Cube.AddComponent();
}
}
but it I cant work out how to attach it to an individual game object ( Cube1, Cube 2 etc) using the random array
Mucho Help would be appreciated
Cheers
Paul The Belt