Hello, My current issue is that I get the follow message- “Unexpected symbol ‘int’, expecting ‘class’, ‘delegate’, ‘enum’, ‘interface’, ‘partial’, or ‘struct’” I am using this script so I will be able to have an ammo count on my weapon. But, I get the following message. I’ve struggled with this for hours now, and I can’t figure it out. My script is down below. Any help is very much appreciated!
So, right above your if(targetDistance < allowedRange) you have a closing bracket which closes your update method off. Remove that bracket.
Oh, and…your variables at the top are outside your class…They need to be within your class, just outside a method to be global variables. (this is actually where your current error comes from, the rest are fixes you’ll still need to make)
Then don’t import UnityEngine.UI; Declare it at the top as a Using just like the other Using are up there.
I don’t know where you got this script or if you just pieced it together or what…but it’s got a lot of things wrong with it.
Thank you! I fixed a few things, but I’ve still got a few errors. Unexpected symbol ‘>’ expecting identifier, Unexpected symbol ‘<’ expecting identifier, and Unexpected symbol ‘)’ expecting identifier. Also, it was a bit of a shamble. I was using originally a Javascript, but I tried to convert it to C#. But this is what my script looks like now.
If you could help me out a bit more with this, I would really appreciate it!
Just to add, you should use code tags and post your code directly instead of images, I can’t copy and paste text from images
Your GetComponent. has a period before the <. I think UnityScript uses this, however c# doesn’t.
Also to note, your AmmoDisplay is a private GameObject, so currently it’s not going to appear in the inspector to drag and drop. So right now if you ran this, you’ll get a null error.
What code editor are you using? I highly recommend using an IDE with compiler like Visual Studio Community 2017 or MonoDevelop in order to have your error-causing code underlined in red.
You seem to be struggling with your curly brace matching and indenting. While indents and whitespace make no difference to the compiler, curly braces make a huge difference. Make sure you have one closing curly brace for every opening curly brace.
Try using this style to help you stay organized:
public class Example : MonoBehaviour
{
private bool condition;
private void Awake()
{
}
private void Update()
{
if(condition)
{
}
}
}
Did you disable the error checking then? VS 2017 by default will red underline all of your C# errors. Things like closing curly braces are usually automatically generated as well.