#how can i randomly put coins in the air
1 messages · Page 1 of 1 (latest)
hi
bruh
ok what can i do
OK so let me get this right, you want the coins to spawn randomly, right?
within a certain radius
exaclty
LETS DO IT
alright firstly, do you know what arrays are?
do you know what ints are
wtf is arrays
yep
do you know what gameobjects are
ofc
just double checking to see how in depth i have to explain this 😄
i'm a games programming student so im learning this stuff aswell
cool
alright, firstly you want to make a private gameobject called coins
should look something like this
don't forget the [SerializeField] and the [] on the gameobject
and obviously call the points coins
and
have you done that?
yep
Okauy
okay
the thing is im not sure how this is gonna work as its 2d but im still happy to try
ok
and
should look like this
it does
hello?
ok lets complete
sorry
OK now make 3 gameobjects as children of Waypoints or whatever you call it
and call them Spawnpoint 1, 2 and 3
should look something like this
and
so when you click the down triangle everything collapses
ok
does that happen?
what?
and
and
and
then do it for every waypoint
it can be the same colour
should be the same colour*
then send me a screenshot
make them the same colour and move them to where you want the coins to spawn
show me your whole screen
ok make all the colors the same for the spawnpoints
and
just for now, put 1 in each corner
of the map?
and
also you need to learn putting stuff in right folders but well do that later
make an empty game object called 'Spawner' and drag the script on to Spawner
and
you did that, yea?
yea
okay now go to the inspector, it should look like this
click the + and drag the waypoints you made in there
drag it
yes just drag the script to the inspector
bro this is what it looks like this
did you do it then
show me the script
done
you need to name your scripts something easier and memorable
thats nothing xD
and not so rude
ok
wait go back to unity quickly
why?
done
and
in your start function you need to do coin = GameObject.FindGameObjectsWithTag("waypoint");
so it finds all of the waypoints you created
now you need to make a vector2 function called getRandomSpawnPoints or something similar
public or private
up to you
i will do public
private makes more sense as it'll only be accessed in this script
U SAID ITS UP TO YOU
now inside your new function you need to make a Vector2 called pos
dont know i think Vector2.pos
Vector2 pos;
dont know how to make
it
ok
and
pos.x = coins[Random.Range(0, points.Length)].transform.position.x + Random.Range(-7, 7)```
something like that
wow thx i will steal that
change points.length to coins.length
didnt understand
like what i change
what part
points.length to fucking coins.length
its crossed out in the picture man
show me your script
what do i change it into
when you screenshot code show me the line numbers
you see in line 22
its the same code as the one ive screenshotted multiple times and shown you what to change what into
do the same in your code
now you need to do the same for Y
but you don't want random y right?
if you don't, remove the + Random.range at the end
remmove the ramdon range at the end
wdym
i thought you were a good man
ohhhhh
because ur not doing what im saying to do
cuz i dont understand
you don't know basic coding so learn that before you start projects i guess
anyways lets complete
type 'StartCoroutine(SpawnEnemies());' in the start function
and
and
show me the script
the whole s cript
bruh now i have to go study
okay
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnPoints : MonoBehaviour {
#region Private Variables
[SerializeField] private GameObject[] points;
[SerializeField] private GameObject[] enemies;
private int spawnCount, enemyCount;
private float spawnTimer;
[SerializeField] private Animator anim;
#endregion
void Start() {
points = GameObject.FindGameObjectsWithTag("waypoint");
spawnCount = 10;
StartCoroutine(SpawnEnemies());
}
void Update() {
}
IEnumerator SpawnEnemies() {
while (enemyCount < 1) {
var spawnedEnemy = Instantiate(enemies[0], getRandomSpawnPoint(), Quaternion.identity);
spawnedEnemy.transform.parent = GameObject.Find("====== ENEMY ======").transform;
spawnedEnemy.name = $"Enemy " + enemyCount;
yield return new WaitForSeconds(0.15f);
enemyCount += 1;
}
}
private Vector3 getRandomSpawnPoint() {
Vector3 pos;
pos.x = points[Random.Range(0, points.Length)].transform.position.x + Random.Range(-7, 7);
pos.y = points[Random.Range(0, points.Length)].transform.position.y;
pos.z = points[Random.Range(0, points.Length)].transform.position.z + Random.Range(-7, 7);
return pos;
}
}```
heres my whole script
you can figure it out, its super easy i believe in you
i am back
LETS DO IT
ok sorry
what abt now?
I just got out of the shower man
ok ok
when are u free then?
Probably not today