#```cs
1 messages · Page 1 of 1 (latest)
private GameObject[] bullets;
private GameObject shootbullet;
int FireRate = 0;
void Update()
{
if (FireRate == 60)
{
StartCoroutine(SpawnBullets());
FireRate = 0;
}
else
{
FireRate++;
}
}
IEnumerator SpawnBullets()
{
yield return new WaitForSecondsRealtime(0);
//makes custom keyword.
shootbullet = Instantiate(bullets[0]);
//actually sets the stats
shootbullet.transform.position = this.transform.position;
shootbullet.transform.rotation = this.transform.rotation;
}```
aw how come your code has the pretty colors?
Anyways, A question I had about your psudocode, was that you put the start functionin an IEnumerator?
both, at the same time?
sorry, I don't mean simultaneous. I mean, like, Making it a Coroutine won't stop it from activating at it's normal time?
It would activate at it's normal time as an appropriate Coroutine - it'd be started as a coroutine.
gah friggin. I just realized I forgot to tie my code to the inputs
Ideally, you wouldn't want to be repeatedly starting coroutines but instead have a single coroutine for the life of the event and do what you need to in a loop.
So in your case, you'd: cs Update: Get input and save it to some field SpawnBullet: loop forever till this component is disabled etc loop while field that has input isnt valid yield to not freeze Spawn bullet since proper input was pressed yield delay OnEnabled: StartCoroutine(SpawnBullet) OnDisabled: //Don't need to do anything as a Coroutine is disabled when the MonoBehaviour is disabled
wait, that's why the waitforseconds wasn't fixing the fire rate before. it was, it was just also creating about five million coroutines all waiting for seconds.
so eventually, it'd just look like a steady stream
Okay I think I'm getting this down, I've just got one minor issue
ffs nvm
Return type needs to be IE... else it's a regular function etc
Yeah.
I left the yield return in there
yeah
???
I'm not asking for a bool tho
ALL of those red lines have the same error
First off, Update.
Second, you've got some field called Input that's of type bool.
Third, hopefully "LookVertical" and "LookHorizontal" are valid.
yeah the speed at which everyone answered that makes me think this is a common mistake ^^
yup, definitely. That's how I get my ship to spin around. Had to learn Quadrophilliac Slurping or something
public class Shooting : MonoBehaviour
{
[SerializeField]
private GameObject[] bullets;
private GameObject shootbullet;
private bool HasInput;
[SerializeField]
float FireRate = 0.05f;
IEnumerator Start()
{
while (true)
{
yield return new WaitForSecondsRealtime(FireRate);
while (HasInput == false)
{
yield return null;
}
SpawnBullets();
}
}
void Update()
{
if (Input.GetAxisRaw("LookVertical") != 0 || Input.GetAxisRaw("LookHorizontal") != 0)
{
HasInput = true;
}
else
{
HasInput = false;
}
}
void SpawnBullets()
{
//makes custom keyword.
shootbullet = Instantiate(bullets[0]);
//actually sets the stats
shootbullet.transform.position = this.transform.position;
shootbullet.transform.rotation = this.transform.rotation;
}
}```
This should look alright?
It's working how I intend for it to, at least
If it floats your boat, that's all that matters 
Could just do cs HasInput = Input.GetAxisRaw("LookVertical") != 0 || Input.GetAxisRaw("LookHorizontal") != 0;btw.
thank you very much for teaching me the smarter ways of the programmer.
oh what the fuck
sneaky developer sneakrets
alright, now tell me how to do fun colors in my codeblock text like you did at the top
I mean... cs if (the stuff in here are true) something = true else something = falsemight as well be... cs something = the stuff in here
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Inline Code
public class Shooting : MonoBehaviour
{
[SerializeField]
private GameObject[] bullets;
private GameObject shootbullet;
private bool HasInput;
float FireRate = 0.05f;
IEnumerator Start()
{
while (true)
{
yield return new WaitForSecondsRealtime(FireRate);
while (HasInput == false)
{
yield return null;
}
SpawnBullets();
}
}
void Update()
{
HasInput = Input.GetAxisRaw("LookVertical") != 0 || Input.GetAxisRaw("LookHorizontal") != 0;
}
void SpawnBullets()
{
//makes custom keyword.
shootbullet = Instantiate(bullets[0]);
//actually sets the stats
shootbullet.transform.position = this.transform.position;
shootbullet.transform.rotation = this.transform.rotation;
}```
oh you beautiful fucker
okay thank you so so much wise teacher for your wisdom and free time
Looks good-to-go 