Help with space shooter typing game.

Ok, so i’ve been stuck on this problem for two days now. I’m new to C# and if anyone could help me out it would be greatly appreciated.

What i’m trying to accomplish: I’m doing a top down 2D space shooter typing game. I’m trying to get the player to press the correct sequence of keys stored in an array, and the correct sequence is generated using a random number generator. Level one is 5 letters, level two is 10, etc. If the player presses the wrong key, he takes damage. If the player presses the right key, the spaceship moves to the x axis the “enemy” letter is at, shoots, and then returns to its starting position.

Issues that i’m having: When I generate a random number, it always seems to be the same one. I can shoot 5 times, which is what I want, but it’s 5 times with the same letter. Also, i’m not sure how to get the x location of a randomly spawned “enemy” letter, and then move my player to that x location to shoot, and then move back to the beginning location.

My player movement class which stores the letters in an array, has the player fire, and then return:
```csharp
**using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

private Vector3 pos;
private Transform tr;

public GameObject Bullet;
public GameObject BulletPosition1;
public GameObject BulletPosition2;


float y = -4.49f;
public float g;
private bool _keyPressed = false;

EnemySpawner enemySpawn = new EnemySpawner();
int count = 0;
Vector3 position;
public string[] keyPress = {"w","a","s","d"};
public Random rnd = new Random ();



void Start ()
{
    int randomNumber = rInt (0, keyPress.Length);
    FirstFunction(randomNumber);
}

void Update ()
{
    if (transform.position.x <= -4.3f) {
        transform.position = new Vector2(-4.3f, transform.position.y);
    } else if (transform.position.x >= 4.3f) {
        transform.position = new Vector2(4.3f, transform.position.y);
    }

}
void FirstFunction(int j){
    StartCoroutine (WaitForKeyDown (keyPress [j]));
}
IEnumerator WaitForKeyDown(string _button)
{
    while (!_keyPressed && count <5) {
        if(Input.GetKeyDown (_button)) {

            g = enemySpawn.getEnemy ();
            position.x = g;
            position.y = y;
            this.transform.position = position;
           
            GameObject bullet01 = (GameObject)Instantiate (Bullet);
            bullet01.transform.position = BulletPosition1.transform.position;
           
            GameObject bullet02 = (GameObject)Instantiate (Bullet);
            bullet02.transform.position = BulletPosition2.transform.position;
            count++;
            Start ();

        }
        yield return null;
    }
}

public static int rInt(int min, int max){
    int t = Random.Range (min, max);
        return t;
}

}**
** **And my EnemySpawner class which spawns the enemy letter at a random x location at the top of the screen:** **csharp
**using UnityEngine;
using System.Collections;

public class EnemySpawner : MonoBehaviour {
public GameObject EnemyGO;

float maxSpawnRateInSeconds = 8f;
public Vector2 temp;


public float f;
public GameObject taggedObject;



void Start () {
    Invoke ("SpawnEnemy", maxSpawnRateInSeconds);

    InvokeRepeating ("IncreaseSpawnRate", 0f, 30f);

}


void Update () {

}

void SpawnEnemy(){

    Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (0, 0));

    Vector2 max = Camera.main.ViewportToWorldPoint ( new Vector2 (1, 1));

    GameObject anEnemy = (GameObject)Instantiate (EnemyGO);
    f = Random.Range (min.x, max.x);
    temp = new Vector2 (f , max.y);
    anEnemy.transform.position = temp;

    ScheduleNextEnemySpawn ();

}

void ScheduleNextEnemySpawn(){
    float spawnInNSeconds;

    if (maxSpawnRateInSeconds > 1f) {
        spawnInNSeconds = Random.Range (1f, maxSpawnRateInSeconds);
    } else
        spawnInNSeconds = 1f;
    Invoke ("SpawnEnemy", spawnInNSeconds);

}

void IncreaseSpawnRate(){
    if (maxSpawnRateInSeconds > 1f) {
        maxSpawnRateInSeconds --;
    }

    if (maxSpawnRateInSeconds == 1f)
        CancelInvoke ("IncreaseSpawnRate");
}


public float getEnemy(){
    return f;
}

}**
```

One thing about the random problem: Start() is only called once per object instantiation. In Start you call rInt() to get your random number and store it in a variable. That won’t change until you call rInit() again.

Thanks for the help. Any recommendation on how to implement it?

Sure… but they are basically expressing the very ideas that you wrote in your first paragraph. I would break it down into steps, and start trying out one thing at a time, using the learning section on the Unity site or other code examples you find on the net. If you cannot do one of the things, move onto the next.