Unexpected symbol 'return' in class, struct, or interface member declaration
I've got a book to learn Unity basics. After retyping an IA script, i see that it's full of errors.
It's supposed to be a script which sets the "joueurVu" variable to true when the First Person Controller is at 5 meters of the alien.
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false;
public GameObject joueur;
// Use this for initialization
void Start () {
joueur = GameObject.Find("First Person Controller");
}
// Update is called once per frame
void Update () {
if (getDistance() < 5) {
joueurVu = true;
print ("Joueur Vu!");
}
}
return Vector3.Distance(joueur.transform.position Transform.position);
float getDistance(){
}
}
Here's the others errors I got https://gyazo.com/aad1ef1bb54ef9fee77fd3c2bc2a3ee1
It appears that the book is outdated to Unity 4, i'm at Unity 5 and the interface is quite different, but it's in french and it is a lot more comfortable. What should I do?
Answer by gjf · Jan 31, 2016 at 02:51 PM
it's important that you post the complete error message - it includes line number/character position of the error which will help us spot the problem and help you faster.
in this case, it looks like you've missed a comma on line 23. when you're copying tutorials, you need to be certain that you copy EVERYTHING ;)
hope that helps.
Okay thanks for the advice :) However what do you mean by posting the complete error message ? I even made a snapshot of the error window
Answer by allenallenallen · Feb 01, 2016 at 07:22 PM
The book might be outdated but it's more like you didn't copy EVERYTHING in the RIGHT ORDER.
This part is all wrong:
return Vector3.Distance(joueur.transform.position Transform.position);
float getDistance(){
}
The return line should be inside of the getDistance. And if you want to return a float, you have to give inputs. But I don't understand why you made a new return float that only uses Vector3.Distance which does the exact same thing as Vector3.Distance. Why not just use Vector3.Distance?
Fixed version:
// Update is called once per frame
void Update () {
if (Vector3.Distance(joueur.transform.position Transform.position) < 5) {
joueurVu = true;
print ("Joueur Vu!");
}
}
Delete the return and getDistance lines. They aren't needed.
Done but now I have new errors https://gyazo.com/9cb4ffd8f49c5f0a8834e57332dcc333 I don't get why do I have a parsing error line 25, I have checked several times if I forgot semicolon, but I put those all
// Update is called once per frame
void Update () {
if (Vector3.Distance(joueur.transform.position Transform.position) < 5) {
joueurVu = true;
print ("Joueur Vu!");
}
}
}
Seems like the position after the Transform.position it at the wrong place
Answer by Lazerty · Feb 12, 2016 at 09:02 AM
I took a code from an other source, but now I have a parsing error despite no accolade are missing. I searched for missing accolades, semicolons or bad syntax for a while, and I discovered that parsing error might be because of conflicted files (in any case what does it exactly mean) but the parsing error is still there. Here's my code:
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false; //le joueur est-il repéré?
public GameObject joueur; //le joueur
// Use this for initialization
void Start () {
/*On recherche le joueur avec son nom et la fonction Find*/
joueur = GameObject.Find("First Person Controller");
}
// Update is called once per frame
void Update () {
// If the player has been sighted and isn't dead...
if(enemySight.personalLastSighting != lastPlayerSighting.resetPosition && playerHealth.health > 0f)
// ... chase.
Chasing();
}
}
void using UnityEngine.Chasing;
{
// Create a vector from the enemy to the last sighting of the player.
Vector3 sightingDeltaPos = enemySight.personalLastSighting - transform.position;
// If the the last personal sighting of the player is not close...
if(sightingDeltaPos.sqrMagnitude > 4f)
// ... set the destination for the NavMeshAgent to the last personal sighting of the player.
nav.destination = enemySight.personalLastSighting;
// Set the appropriate speed for the NavMeshAgent.
nav.speed = chaseSpeed;
// If near the last personal sighting...
if(nav.remainingDistance < nav.stoppingDistance)
{
// ... increment the timer.
chaseTimer += Time.deltaTime;
// If the timer exceeds the wait time...
if(chaseTimer >= chaseWaitTime)
{
// ... reset last global sighting, the last personal sighting and the timer.
lastPlayerSighting.position = lastPlayerSighting.resetPosition;
enemySight.personalLastSighting = lastPlayerSighting.resetPosition;
chaseTimer = 0f;
}
}
}
Also, sometimes when i pass my mouse on the void before using UnityEngine.Chasing;, it tells me that this is an unexpected void, and sometimes it doesnt
Your answer
Follow this Question
Related Questions
Resolution does not change when the DropdownMenu option is selected in build. 0 Answers
+= operator on transform.localPosition results in random values 1 Answer
parsing error 1 Answer
(31,16): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `=' 2 Answers
how to provide axes input to fpscontroller according to maincamera y rotation ? 0 Answers