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 /
avatar image
0
Question by SeabearStudios · Oct 10, 2016 at 05:11 AM · c#parsing error

Strange Parsing Error

So I am making a game using the "Let's Try Assignments" course and instead of hurting the blocks I just apply force. I want to apply a positive force to push when left mouse is pressed, and a negative to pull when right mouse is pressed. The left mouse is functional and I tried to copy and paste the script over and change around some variables, inputs, and what not and I believe I got it working, however the sound and visuals have a parsing error after I triple checked my script. It says that I also have an error with putting private in front of IENumerator but I think that's because of the parsing error. Here is the whole script, the last part is the part where the parsing error is, but I will include it all because I might have to change something else.

 using UnityEngine;
 using System.Collections;
 
 public class RaycastShootComplete : MonoBehaviour {
 
     public int gunDamage = 1;                                            // Set the number of hitpoints that this gun will take away from shot objects with a health script
     public float fireRate = 0.25f;                                        // Number in seconds which controls how often the player can fire
     public float weaponRange = 50f;                                        // Distance in Unity units over which the player can fire
     private float neghitForce;                                            // Amount of force which will be added to objects with a rigidbody pulled by the player
     public float hitForce = 100000f;                                    // Amount of force which will be added to objects with a rigidbody shot by the player
     public Transform gunEnd;                                            // Holds a reference to the gun end object, marking the muzzle location of the gun
 
     private Camera fpsCam;                                                // Holds a reference to the first person camera
     private WaitForSeconds shotDuration = new WaitForSeconds(0.07f);    // WaitForSeconds object used by our ShotEffect coroutine, determines time laser line will remain visible
     private AudioSource gunAudio;                                        // Reference to the audio source which will play our shooting sound effect
     private LineRenderer laserLine;                                        // Reference to the LineRenderer component which will display our laserline
     private float nextFire;                                                // Float to store the time the player will be allowed to fire again, after firing
 
     void Start () 
     {
         // Get and store a reference to our LineRenderer component
         laserLine = GetComponent<LineRenderer>();
 
         // Get and store a reference to our AudioSource component
         gunAudio = GetComponent<AudioSource>();
 
         // Get and store a reference to our Camera by searching this GameObject and its parents
         fpsCam = GetComponentInParent<Camera>();
     }
     
 
     void Update () 
     {
         // Check if the player has pressed the fire button and if enough time has elapsed since they last fired
         if (Input.GetButtonDown("Fire1") && Time.time > nextFire) 
         {
             // Update the time when our player can fire next
             nextFire = Time.time + fireRate;
 
             // Start our ShotEffect coroutine to turn our laser line on and off
             StartCoroutine (ShotEffect());
 
             // Create a vector at the center of our camera's viewport
             Vector3 rayOrigin = fpsCam.ViewportToWorldPoint (new Vector3(0.5f, 0.5f, 0.0f));
 
             // Declare a raycast hit to store information about what our raycast has hit
             RaycastHit hit;
 
             // Set the start position for our visual effect for our laser to the position of gunEnd
             laserLine.SetPosition (0, gunEnd.position);
 
             // Check if our raycast has hit anything
             if (Physics.Raycast (rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
             {
                 // Set the end position for our laser line 
                 laserLine.SetPosition (1, hit.point);
 
                 // Get a reference to a health script attached to the collider we hit
                 ShootableBox health = hit.collider.GetComponent<ShootableBox>();
 
                 // If there was a health script attached
                 if (health != null)
                 {
                     // Call the damage function of that script, passing in our gunDamage variable
                     health.Damage (gunDamage);
                 }
 
                 // Check if the object we hit has a rigidbody attached
                 if (hit.rigidbody != null)
                 {
                     // Add force to the rigidbody we hit, in the direction from which it was hit
                     hit.rigidbody.AddForce (-hit.normal * hitForce);
                 }
             }
             if (Input.GetButtonDown("Fire2") && Time.time > nextFire) 
             {
                 // Update the time when our player can fire next
                 nextFire = Time.time + fireRate;
 
                 // Start our ShotEffect coroutine to turn our laser line on and off
                 StartCoroutine (ShotEffect());
 
                 // Create a vector at the center of our camera's viewport
                 Vector3 rayOrigin2 = fpsCam.ViewportToWorldPoint (new Vector3(0.5f, 0.5f, 0.0f));
 
                 // Declare a raycast hit to store information about what our raycast has hit
                 RaycastHit hit2;
 
                 // Set the start position for our visual effect for our laser to the position of gunEnd
                 laserLine.SetPosition (0, gunEnd.position);
 
                 // Check if our raycast has hit anything
                 if (Physics.Raycast (rayOrigin, fpsCam.transform.forward, out hit2, weaponRange))
                 {
                     // Set the end position for our laser line 
                     laserLine.SetPosition (1, hit2.point);
 
                     // Get a reference to a health script attached to the collider we hit
                     ShootableBox health = hit2.collider.GetComponent<ShootableBox>();
 
                     // If there was a health script attached
                     if (health != null)
                     {
                         // Call the damage function of that script, passing in our gunDamage variable
                         health.Damage (gunDamage);
                     }
 
                     // Check if the object we hit has a rigidbody attached
                     if (hit2.rigidbody != null)
                     {
                         // Add pulling force to the rigidbody we hit, in the direction from which it was hit
                         hit2.rigidbody.AddForce (-hit2.normal * neghitForce);
                     }
                 }
             {
                 // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange
                 laserLine.SetPosition (1, rayOrigin + (fpsCam.transform.forward * weaponRange));
             }
         }
 
 
             IEnumerator ShotEffect;
             {
                 // Play the shooting sound effect
                 gunAudio.Play ();
 
                 // Turn on our line renderer
                 laserLine.enabled = true;
 
                 //Wait for .07 seconds
                 yield return shotDuration;
 
                 // Deactivate our line renderer after waiting
             laserLine.enabled = false;            
             }


The error code is (135,25): error CS8025: Parsing error (which is that last line)

Can replies be in C# only? Please tell me how to fix :) thx.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · Oct 10, 2016 at 05:12 AM

you have ; instead of () in front of ShotEffect declaration

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 SeabearStudios · Oct 10, 2016 at 01:26 PM 0
Share

Ah, I see. Whenever I get home I will test that and get back to you :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

i am pretty sure that this is right but..... 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer


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