Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
-1
Question by BDX777 · Dec 21, 2013 at 04:47 PM · c#error

Semicolons are seen as an unexpected symbol

I'm trying to code a script that makes a light flash when I left-click, because I'm trying to simulate a gun muzzle.

 using UnityEngine;
 using System.Collections;
 
 public class LightFlash : MonoBehaviour {
 
     public class LightIntensityDefault = 2;
         public class LightFlashIntensity = float;
 
     void Update () 
     {
         if(Input.GetMouseButtonDown("Fire2"))
             LightFlashIntensity = 4;
         WaitForEndOfFrame
             LightFlashIntensity = LightIntensityDefault;
         light.intensity = LightFlashIntensity;
     }
 }
Comment
Add comment · Show 6
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 Jessy · Dec 21, 2013 at 05:05 PM 1
Share

It looks like you're plugging in random keywords and hoping that the computer takes your meaning. The compiler isn't as smart as you want it to be, but aside from helping it to understand what you mean, you also need to not throw in arbitrary nonsense.

avatar image vexe · Dec 21, 2013 at 05:08 PM 0
Share

This is obviously a joke.

avatar image ozturkcompany · Dec 21, 2013 at 06:38 PM 0
Share

damn it! i was looking at the screen like was there ever any definions like that,lol

avatar image sdgd · Dec 21, 2013 at 07:07 PM 1
Share

I'll say it you are rare person to try and show some effort @BDX777

I don't understand why are you criticized so much.

your Q is perfectly normal and shouldn't receive thumbs down.

but as you are in learning I'll show just simple tips.

Declare stuff like this:

 public float LightIntensityDefault = 2f; // default is now set to float and you can only use part numbers as default
 public float LightFlashIntensity = 2f; // same as above

In Update code:

 void Update (){
     if(Input.Get$$anonymous$$ouseButtonDown(0)){
         LightFlashIntensity = 4f;
     }
     // WaitForEndOfFrame -- stuff that aren't code should be marked as comment as I did with "//"
     // everything after // will be ignored by compiler. IN THAT LINE of code
     // and it really shouldn't wait till end of frame and to do it it would have to go to the end of function.
     // that's why you get freeze when you make infinity loop as next frame is not shown till the code isn't finished
     LightFlashIntensity = LightIntensityDefault;
     Light ReferenceToComponent = transform.GetComponent<Light>(); // you must have Light component attached in your GameObject that this script is attached.
     ReferenceToComponent.intensity = LightFlashIntensity;
 }

and like @Julien.Lynge said you should check those tutorials.

if you learned something and will show more effort next time I will leave you thumbs up, otherwise I'll remove it. and you'll need to still wait for moderation in queue.

and as always happy coding.

avatar image BDX777 · Dec 21, 2013 at 09:42 PM 0
Share

@sdgd Thank you, I was trying to declare some variables and didn't know how. Also I used "WaitForEndOfFrame" because I was trying to have a script that made the light flash and then go back to normal, because it's a laser gun that still emits light, but flashes bright when left clicking, simulating semi-auto muzzle-flashing.

And yeah I'm totally new at C#, I just started a few days ago. It's good to see some people cutting me a little slack, I kinda just jumped into unity after gaining some experience with Game $$anonymous$$aker coding.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by tanoshimi · Dec 21, 2013 at 05:45 PM

@Jessy, @Vexe - to be fair, newbie posters here are often criticised for asking "Plz will somebody write a script to do xxx" when they haven't even had a go themselves first (and, many times, kind people will give them the exact script they ask for).

At least the OP has demonstrated at least some attempt to try to help themselves before asking for help. I agree it is somewhat baffling, but they've had a go!

@BDX777 - your script is, essentially, nonsense. It's not a single error - you're trying to assign an integer (2) and a type (float) to a class (LightIntensittDefault and LightFlashIntensity), you're using a Yield instruction in an Update() function, you haven't put semicolons at the end of instructions, or brackets to denote conditional blocks, you're trying to assign an integer (4) to a class that you previously tried to declare as a float...

I think you need to take a step back and follow some coding tutorials because, even if somebody here were to write this script for you, I fear that it wouldn't be long before you encounter another problem.

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 Julien-Lynge · Dec 21, 2013 at 06:33 PM 3
Share

I'm converting @tanoshimi's comment to an answer, because it really is the solution to your problem. The best way for you to move forward is to watch a few tutorial videos and do some training - there is unfortunately no shortcut that will let you make a game without an underlying knowledge of how to program.

Here are some suggestions to get you started:

  • 3DBuzz (hover over the Unity dropdown) - http://www.3dbuzz.com/vbforum/sv_home.php

  • Lynda - https://www.lynda.com/

  • BurgZergArcade - http://www.burgzergarcade.com/

  • Unity3DStudent - http://www.unity3dstudent.com/

  • UnityGems - http://unitygems.com/

  • CGCookie - http://cgcookie.com/unity/

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

23 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

Related Questions

Array index out of range error 1 Answer

Getting index of the smallest number in a list 1 Answer

error on getint c# 0 Answers

Object reference not set to an instance of an object in functions 1 Answer

SetActive() Object reference not set to an instance of an object. 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