Hail to thee o/
I’ve been fighting with this thing for days, checked various tutorials, searched from older posts and still no vail.
I’m trying to create game level where three controller keys (left,up,right) are randomized every 30 seconds.
Randomized keys what i’m trying to use are alphanumeric and looks like I can’t even do that because INT doesn’t accept letters. Tried even with only numbers but no luck…
My “lottery” script is fully functioning and even debug shows which correct key is chosen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SatunnainenOhjaus : MonoBehaviour
{
// Name is RandomController in finnish
public string[] RandomPick = new string[36] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
// For testing purposes...
// public string[] RandomPick = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
bool Waiting = false;
public int Rerolling; // rolls array number;
public int Desperate = 1; // for further debugging the problem
IEnumerator Reroll()
{
Waiting = true;
yield return new WaitForSeconds(3); // counter will be longer when this will work
// Getting random value from string
System.Random random = new System.Random();
Rerolling = random.Next(RandomPick.Length);
// Showing on console the result which should be available for other script but no vail
Debug.Log(RandomPick[Rerolling]);
Waiting = false;
}
void Update()
{
if (Waiting == false)
{
StartCoroutine(Reroll());
}
}
}
And incomplete script wich change movement button what is also displayed on UI is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Vasen : MonoBehaviour
{
// Name is Left in finnish
// UI is for future use after this major problem is solved
public GameObject Left;
public SatunnainenOhjaus RandPick;
void Awake()
{
RandPick = GetComponent<SatunnainenOhjaus>();
}
void Start()
{
Debug.Log("Chosen letter/number is: " + RandPick.Rerolling); // RandPick.Desperate gives same error
}
}
But! I’m getting NullReferenceException error and reference is removed from inspector. So I assume It just need more time for lottery script (SatunnainenOhjaus) to get that random number/character. Used Inumerator for Vasen script with a slightly longer time. That didn’t work out.
Next I tried to get normal public int value 1. call it Desperate and Visual Studios Intellisense showed connection, no errors on code even still that didn’t work.
I know that INT can only numbers but no luck what so ever with string holding numbers only.
Edit: I’ve added scripts on empty gameobjects and referred them in inspector to see if originally children objects behaved someway differently. Same thing’s going on.
So what should I do to get this “legendary 15 minutes only” project to work?