alex_aom
alex_aom
CC#
Created by alex_aom on 1/20/2023 in #help
Can't find a GameObject's transform & rotation in Unity?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WaveSpawner : MonoBehaviour
{
public Transform enemyPrefab;
private float gametime;
private float initialGametime = -2f;
public int timeBetweenWaves = 1;
public Text waveCountdownText;
private int waveIndex = 0;
private int wavesSpawned = 0;
private float nextWaveSpawnTime;

void Start()
{
gametime = initialGametime;
}

private void Update()
{
GameObject spawnPoint = GameObject.Find("SpawnPoint");
nextWaveSpawnTime = Mathf.Floor(waveIndex) * timeBetweenWaves;

if (gametime > nextWaveSpawnTime)
{
waveIndex++;
if (waveIndex >= wavesSpawned)
{
StartCoroutine(SpawnWave(spawnPoint));
wavesSpawned++;
}
}

gametime += Time.deltaTime;
waveCountdownText.text = Mathf.Round(Mathf.Abs(gametime)).ToString();
}

IEnumerator SpawnWave(GameObject spawnPoint)
{
for (int i = 0; i < waveIndex; i++)
{
SpawnEnemy(spawnPoint);
yield return new WaitForSeconds(0.3f);
}
}

void SpawnEnemy(GameObject spawnPoint)
{
Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation);
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WaveSpawner : MonoBehaviour
{
public Transform enemyPrefab;
private float gametime;
private float initialGametime = -2f;
public int timeBetweenWaves = 1;
public Text waveCountdownText;
private int waveIndex = 0;
private int wavesSpawned = 0;
private float nextWaveSpawnTime;

void Start()
{
gametime = initialGametime;
}

private void Update()
{
GameObject spawnPoint = GameObject.Find("SpawnPoint");
nextWaveSpawnTime = Mathf.Floor(waveIndex) * timeBetweenWaves;

if (gametime > nextWaveSpawnTime)
{
waveIndex++;
if (waveIndex >= wavesSpawned)
{
StartCoroutine(SpawnWave(spawnPoint));
wavesSpawned++;
}
}

gametime += Time.deltaTime;
waveCountdownText.text = Mathf.Round(Mathf.Abs(gametime)).ToString();
}

IEnumerator SpawnWave(GameObject spawnPoint)
{
for (int i = 0; i < waveIndex; i++)
{
SpawnEnemy(spawnPoint);
yield return new WaitForSeconds(0.3f);
}
}

void SpawnEnemy(GameObject spawnPoint)
{
Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation);
}
}
Assets\Scripts\WaveSpawner.cs(51,45): error CS1061: 'GameObject' does not contain a definition for 'position' and no accessible extension method 'position' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)
5 replies
CC#
Created by alex_aom on 1/18/2023 in #help
❔ More cores on unity
5 replies
CC#
Created by alex_aom on 1/18/2023 in #help
How to take 2 outputs from a function
I can't work out how to take 2 outputs from a function (3rd line isn't valid)
int i;
int j;
[i,j] = randomStart(MATRIX_ROWS, MATRIX_COLUMNS);

int[,] randomStart(int MATRIX_ROWS, int MATRIX_COLUMNS)
{
int randStart;
int x3;
int y3;
randStart = Random.Range(0, 3);
switch (randStart)
{
case 0:
x3 = 2;
y3 = Random.Range(1, MATRIX_COLUMNS - 1);
break;
case 1:
x3 = 9;
y3 = Random.Range(1, MATRIX_COLUMNS - 1);
break;
case 2:
x3 = Random.Range(1, MATRIX_ROWS - 1);
y3 = 2;
break;
case 3:
x3 = Random.Range(1, MATRIX_ROWS - 1);
y3 = 9;
break;
}

int[,] output = new int[x3,y3];
return output;
}
int i;
int j;
[i,j] = randomStart(MATRIX_ROWS, MATRIX_COLUMNS);

int[,] randomStart(int MATRIX_ROWS, int MATRIX_COLUMNS)
{
int randStart;
int x3;
int y3;
randStart = Random.Range(0, 3);
switch (randStart)
{
case 0:
x3 = 2;
y3 = Random.Range(1, MATRIX_COLUMNS - 1);
break;
case 1:
x3 = 9;
y3 = Random.Range(1, MATRIX_COLUMNS - 1);
break;
case 2:
x3 = Random.Range(1, MATRIX_ROWS - 1);
y3 = 2;
break;
case 3:
x3 = Random.Range(1, MATRIX_ROWS - 1);
y3 = 9;
break;
}

int[,] output = new int[x3,y3];
return output;
}
6 replies
CC#
Created by alex_aom on 1/17/2023 in #help
Resizing an array
I have declared what I think is an array of integers int[] validCoords = new int[1]; I believe this is a 1d array with 1 entry. How would I resize this?
32 replies