- Home /
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;
}
}
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.
damn it! i was looking at the screen like was there ever any definions like that,lol
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.
@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.
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.
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/