#i have three
1 messages · Page 1 of 1 (latest)
Yes. One is closing the aim method, one is closing the class these methods are in. The third one is unnecessary, unless this is a nested class or you are using a namespace (I'm assuming you aren't), and you do not have a closing brace on Shoot.
just to be sure, when you say brace, you mean this? {}
Yes
i am not using namespace for shoot and aim
when i remove the brace, unity give me a error, requiring the brace i removed
Yes. Removing it is not enough. That bracket is needed, but at the end of Shoot, not at the very end.
i mean, when i do what you say it give me a couple of errors, unless i did it wrong
Have you added the closing bracket at the end of Shoot?
void Shoot()
{
if (Input.GetButtonDown("Fire1") && ammoAmount > 0)
{
Instantiate(bullet, SpawnBullet.position, transform.rotation);
shootFx.Play();
ammoAmount -= 1;
ammo[ammoAmount].gameObject.SetActive(false);
}
}
if (Input.GetKey(KeyCode.R))
{
ammoAmount = 3;
for (int i = 0; i <= 2; i++)
{
ammo[i].gameObject.SetActive(true);
}
}
it's like this
You are closing the method too early. Remove the bracket you added (before if(Input.GetKey(KeyCode.R)) again and put it at the end of what you just posted. After ammo[i].. etc
I just realized I switched from saying brace to bracket. Sorry, I mean the same thing.
}
void Shoot()
{
if (Input.GetButtonDown("Fire1") && ammoAmount > 0)
{
Instantiate(bullet, SpawnBullet.position, transform.rotation);
shootFx.Play();
ammoAmount -= 1;
ammo[ammoAmount].gameObject.SetActive(false);
if (Input.GetKey(KeyCode.R))
{
ammoAmount = 3;
for (int i = 0; i <= 2; i++)
{
ammo[i].gameObject.SetActive(true);
}
}
like this?
Mate.. you removed 2 braces and put them nowhere.
It is genuinely worse than before. Ignore your errors for a second, go through your class and check if you can make sense of where a opening brace should be and where a closing brace should be. Indent your code properly, it will make it easier.
Otherwise I recommend a basic c# course.