Parsing error CS8205,Parsing Error CS8205
A parsing error occurred when i first ran this script
using UnityEngine;
using System.Collections;
public class Gunshot : MonoBehaviour {
public AudioClip Gun;
private AudioSource source;
void Awake () {
source = GetComponent<AudioSource>();
}
public float timeLeft = 5.0f;
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
source.PlayOneShot(Gun,hitVol);
Answer by gooopil · Apr 10, 2016 at 01:41 AM
If that's the complete script, your missing three curly braces } at the end.
If that's not the complete script, please post the complete script!
@Cluelessguy as a general rule, just like in normal text, your parenthesis, brackets and braces should always come in pairs: an opening and a closing one with your code between them.
Answer by Zoogyburger · Apr 10, 2016 at 01:44 AM
Your code should be formatted like this with all public or private statements at the top and with closing brackets:
public AudioClip Gun;
private AudioSource source
public float timeLeft = 5.0f;
void Awake () {
source = GetComponent<AudioSource>();
}
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
source.PlayOneShot(Gun,hitVol);
}
}
}
Sorry I didn't test the whole code. You did not declare hitVolIt so the program is not going to know what it is. Is is also helpful to copy and paste the entire error.
CS1519 unexpected symbol 'public' in class, struct, or interface member declaration
I forgot a to put in a semicolon. Replace line 3 with
private AudioSource source;
you will get another error stating that hitVol doesn't exist in the context so ins$$anonymous$$d of
source.PlayOneShot(Gun,hitVol);
put
audio.PlayOneShot(Gun, 0.7F);
@Zoogyburger your script is missing the line that declares the class.
Yeah I don't know what it would be, a float, public or private? I've never worked with the new audio system thing so I'm not sure how it would be. I don't see why
source.PlayOneShot(Gun,0.7F);
Wouldn't work
So I guess the whole script would look like:
public AudioClip Gun;
private AudioSource source;
public float timeLeft = 5.0f;
void Awake () {
source = GetComponent<AudioSource>();
}
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
source.PlayOneShot(Gun,0.7F);
}
}
}
Your answer
Follow this Question
Related Questions
Parsing error 1 Answer
Show ad after certain line of code is called 5 times 1 Answer
Coding Errors 1 Answer
Parsing Error 0 Answers
parsing error 1 Answer