Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Lazerty · Feb 01, 2016 at 07:18 PM · scripting problemerrorvector3

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lazerty · Feb 04, 2016 at 04:17 PM 0
Share

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

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lazerty · Feb 04, 2016 at 04:25 PM 0
Share

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

avatar image
0

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

https://gyazo.com/8647a97a68a3eea2b1bdd9ab31b1d5ec

https://gyazo.com/bafa1f641ced9cfeb56d75bcb60ea740

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges