Hi to all members here i am new to Unity and i am creating the tutorial SpaceShooter but of course to learn it better i change some things on my own (e.g i made the hazards explode hitting them with 2 shots increasing the hazard amount at the end of the wave…) and now i want to increase their speed up every time the wave ends
my GameController script is this :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour {
public GameObject hazard;
public Vector3 spawnValues;
public float hazardCount;
public float spawnWait;
public float startWait;
public float waveWait;
public float levelhardtime;
public float levelmany;
public float Maxseries;
public float speedrep;
public float rep;
int j=1;
void Start()
{
StartCoroutine (Spawnwaves ());
}
IEnumerator Spawnwaves ()
{
//rep = hazard.GetComponent ().levelDif;
yield return new WaitForSeconds (startWait);
while(true)
{
if (j > 1 && j < Maxseries) {
spawnWait = spawnWait - levelhardtime;
hazardCount = hazardCount + levelmany;
hazard.GetComponent().level = true;
rep = rep + 0.5f;
}
else if (j == Maxseries )
{
hazardCount = 0;
}
for (int i = 0; i < hazardCount; i++)
{
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
j++;
}
}
}
and My Speed script here:
using UnityEngine;
using System.Collections;
public class Speed : MonoBehaviour
{
public float speed;
public Rigidbody rb;
public bool level = false;
public float levelDif;
void Start ()
{
if (level == false)
{
rb = GetComponent ();
rb.velocity = transform.forward * speed ;
}
if (level == true)
{
GetComponent ().rep = levelDif;
rb = GetComponent ();
rb.velocity = transform.forward * speed * levelDif ;
}
}
}
I get this error and the hazards dont move…i know that the problem is on the : GetComponent ().rep = levelDif;
But i dont know what else to add on it. Thanks