#thread
1 messages Ā· Page 1 of 1 (latest)
Ok
Ok Im back, sorry someone called me
K
Anyways look in the unity editor in the top left @lean torrent
there should be something called file
Yeah
Open it, find build settings and then click add open scenes
Ok I clicked add open scenes
Basically it sets that game scene as scene 0. Remember how earlier I told you to write the SceneManager.LoadScene(0); and it had 0 in it? Now it opens that scene every time a collision is detected
Ah ok, when I clicked add open scenes I saw nothing happen is that normal or was something ment to happen?
So it reloads it. Do you have your game scene opened up?
The game itself, yes
Is there a little checkmark?
In scenes in build?
yep
I see a check next to scenes/samplescene
Sample scene is the game right?
I belive it is
You should notice a little 0 by it. Thats how the scene manager will know to load that scene when you ask it to load scene 0
you should rename that
Yeah a 0 on the right
installing a package... and it has "sample Scene" in it, will probably delete / override your scene.
Yeah maybe rename it to whatever you want. Like flappy game
or if you delete the library folder
How do I rename it? I am right clicking on it from the game itself and no option rename
Just go to file -> Save As
Ah
Ok so after that, you have collision working, and a way to reload/restart the scene, whats next?
Well I havenāt actully tested the script yet.
Lets try that now.
Oh
We have a good and bad situation here
Whenever I start the game the ball falls to the ground
So itās in a constant loop of restarting
And even when I move it to the ground
You don't have a way to move the ball correct? so gravity is going to drop it
Oh I forgot to enable my walk and jump script
One sec
Ah I see it now I donāt put the ball on the ground I put ihigher up for time to move it
Perfect
Is there anything else thats missing now?
Now another thing could I add the flappy bird poles randomly generated with simple code or will it take more complex code
And if not do I have to manually add them?
I can tell you that you can generate random positions using Random.Range,
Could that be applied to a 2d map?
let me find a snippit
K
IEnumerator Example()
{
int RandomNumber = Random.Range(1,10);
Debug.Log(RandomNumber);
yield return new WaitForSeconds(2);
StartCoroutine("Example")
}
@lean torrent This generates a random number between 1 and 10 every 2 seconds
So how do I implement that into Generation of poles
Do you know how to instantiate objects?
Basically instantiate would be equivalent of spawning them
Not really.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public GameObject prefab;
void Start()
{
Instantiate(prefab, new Vector3(0,0,0));
}
}
This code spawns a prefab at 0, 0, 0
So Iām gonna make its own seperate script. Do I attach it to an object?
Yes
Which object
If you want. Or create an empty game object
Iāll do that
So once I do that I donāt fully understand āhowā it will spawn an object
Yeah its good that you asked since it can be a bit confusing
Instantiate is like a spawner. If you used /summon in minecraft youll know what I'm talking about
brb
K
You know what a prefab is right?
I belive itās a thing that allows u to create and store a game object in it
Yeah its like a clone
Instantiate(prefab, new Vector3(0,0,0)); is basically what you need. the identity part isnt necessary
Wait I copied and pasted the code for the generation and itās giving me an error message
whats the error?
āThe referenced script on this behavior (Game object āGameObjectā) is missing!
No
yeah ok double click the error
it takes you to where the error came from
don't mix up errors with warnings
Itās yellow text
errors are red and stop the game from working. Yellow warnings are just tips
Oh
that you can usually ignore
Thatās good to know
yeah
Well when I pasted the script is it meant to do anything?
Or do I need to input certain information?
Instantiate(prefab, new Vector3(0,0,0));
Instantiate spawns an object
prefab is the object its going to spawn
and new Vector3 is the coordinates where its going to spawn the object
Yeah
Magic
So you can mix the 2 snippits together
I changed the code u sent me from vector 3 to vector 2 and now there is a red line under it.
Hmm did you take off a 0?
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public GameObject prefab;
void Start()
{
Instantiate(prefab, new Vector2(0, 0, 0), Quaternion.identity);
}
}
Vector2(0,0)
O
So once I run the game this code will start generating stuff at 0,0
yes
Combining both snippits:
IEnumerator Example()
{
int RandomNumber = Random.Range(1,10);
Instantiate(prefab, new Vector2(0,RandomNumber));
yield return new WaitForSeconds(2);
StartCoroutine("Example")
}
what does it do?
It generates a random number then puts it in Vector3 coordinates?
yep
š®
every 2 seconds, it generates a random number, and spawns a prefab at 0 x and RandomNumber y
So how do I use that code to generate poles?
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class Example: MonoBehaviour
{
public GameObject prefab; // assign the prefab
void Start()
{
StartCoroutine("Spawner")
}
IEnumerator Spawner()
{
int RandomNumber = Random.Range(1,10);
Instantiate(prefab, new Vector2(0,RandomNumber));
yield return new WaitForSeconds(2);
StartCoroutine("Spawner");
}
}
I copy and pasted that code and itās redlining everything.
Still some redlines
Ok now
New vector 2, RandomNumber and Spawner are redlined
Then save it and try it. You should be able to tweak it since you understand the gist of it all
Just save it
Is it null reference?
That means a semi colon was expected at line 9
Semi colons are ;
Do you know what the issue is from that?
Now it says Assets/Generation.cs(14,29): error CS1503: argument 2: cannot convert from UnityEngine.Vector2 to āUnityEngine,Transformā
Hmm
And yeah c# needs a semi colon after every line of code
Ok lemme check on my unity, i was typing it all from my poor memory lol, i mightve messed something up
Ok while my unity is booting up, try new Transform(0, RandomNumber);
instead of new Vector2
Now only the word Transform is redlined
Save it
Yeah you should be able to figure it out :)
Ok now it says
CS1729: āTransformā does not contain a constructor that takes 2 arguments
Hmm I'm gonna look up something
Ok
Maybe try quaternion idenitity
So what do I change, Transform?
Sorry Im trying things lol
Itās alright
Im mad it worked
Instantiate(prefab, new Vector2(0,RandomNumber), Quaternion.identity);
The only thing left now would be making the pipes move
lines 19, 2 CS0116 a namespace cannot directly contain members such as fields or methods
As an arrow
Error
Yeah you have something with the same name somewhere
Ok
Does it work or null reference lol
Works
Oo nice
I donāt see nothing generating tho
Do you have a prefab of the pipes?
I do not think so actully
Yeah you need to drag a prefab into the inspector of the pipespawner script
How the heck do I do that
Create a prefab first
I guess make an empty object and child 2 squares into it
Make both of them rectangles
So ones the top pipe and the other is the bottom
And then drag that empty object into the bottom project area where you kept all the scenes/scripts
Lemme know when you did it
then drag that prefab into the inspector
In the script?
So if I just dragged it out into the game nothing would appear right?
there should be a little empty box in the inspector, and drag the prefab in
not yet
Can you open the object with the spawner script in it?
Wait so I put the spawner script on the object
You need to put the spawner script on an empty object
and then a little box will be in the inspector
for the prefab
Ok when I make a game object and drag the script in it says, Canāt add script component āgenerationā because the script class cannot be found
Is the class name also generation
public class generation: MonoBehaviour
the script name and class name have to match
Ok did it
remember to drag the prefab in
play
What was suppose to happen
It makes GameObject1 clone but when I focus on it nothing is there
Hmm is the game object the pipe prefab or the generator?
The game object is a game object and 2 squares
I canāt seem to see the squares either
Can you see it in the scene editor?
Iām gonna remake it
The prefab
Ok now it actully spawns it
In the center of my game
Yeah at 0 x
Only 1 pole is that right?
every 2 seconds?
Could you send the script here
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class Generation : MonoBehaviour
{
public GameObject prefab; // assign the prefab
void Start()
{
StartCoroutine("Spawner");
}
IEnumerator Spawner()
{
int RandomNumber = Random.Range(1, 10);
Instantiate(prefab, new Vector2(0,RandomNumber),Quaternion.identity);
yield return new WaitForSeconds(2);
StartCoroutine("Spawner");
}
}
Hmm well it is instantiating it
And that is in play mode, whenever I turn it off the pole disappears
Yeah its supposed to only spawn the pipes in on play mode. The only thing left is to make the pipes move
Well am I supposed to move it manually in play mode 1 by 1?
You can do it through script, I gtg soon so I can make it
Also its working on my end
I think I might head out itās 2am and My brain is not working
Wanna dm it to me?
I'll send it here, should probably take 2 mins
You need to assign the prefab in the inspector
Yeah and now drag the prefab into the generation script
What do you mean by drag it into the script?
Notice the health area in the inspector?
drag the prefab in there
Ok it should work
It says The Variable prefab of Generation has not been assigned
In red
But I can still load in play mode
No you need to drag it in, in the scene mode or whatever, not in play mode or it wont save
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pipe : MonoBehaviour
{
//YOU NEED A BOX COLLIDER2D ON THE PIPES
void Start()
{
Destroy(gameObject, 7f); //Self Destructs after 7 seconds otherwise lots of lag
}
void Update()
{
transform.Translate(-Time.deltaTime * 1, 0, 0); // moves -1 x every second. You can change the 1 to a 2 or something to speed it up.
}
}
Also theres the pipe script
You can tweak the timings and stuff
Ah
The inspector I just showed you was not in play mode
Iām not doing anything in play mode
StartCoroutine("Spawner"); this?
Is it yellow or red
The error itself was red but Iām able to enter play mode in the script itās not red thereās a symbol near the 10 line
Ummm you can, but I don't know is lol
Still aināt working
You know what
Since this is the dummy version of my flappy bird
Iām gonna install the pipes manually
And in my v2 version Iāll work on the scripts
Itās like 2:30 I canāt even think thank you very much and Iāll cya later
From here, just create a new script called Pipe, paste the pipe code in, and drag it onto the pipes prefab
yeah and gn
@deep dagger I doubt I will ever see this but I presented janky flappy bird to my school with minor adjustments and they loved it
I told them how Iām starting to make new games and they said tomorrow you come up and present a new game concept
So whenever u see this thank you
Glad I could help! :)