- Home /
Error I don't know how to fix
Heres my code:
#pragma strict
var text : GUIText;
var object : GameObject;
var diamond : Sprite;
var circle : Sprite;
var triangle : Sprite;
var square : Sprite;
var number : int;
var spriteRenderer;
var target : Timer;
var AcceptInput : boolean = true;
static var score : int = 0;
static var guiScore : GUIText;
function Start () {
spriteRenderer = object.GetComponent(SpriteRenderer);
number = Random.Range(1,4);
if(number == 1) {
spriteRenderer.sprite = diamond;
}
else if(number == 2) {
spriteRenderer.sprite = circle;
}
else if (number == 3) {
spriteRenderer.sprite = triangle;
}
else {
spriteRenderer.sprite = square;
}
}
function Update () {
if(Input.GetMouseButtonDown(0)) {
if(AcceptInput) {
AcceptInput = false;
text.enabled = false;
target.enabled = true;
Debug.Log("Clicked");
if(object.GetComponent(SpriteRenderer).sprite == diamond) {
score += 1;
guiScore.text = "Score: " + score;
StartCoroutine("YieldTestEnumerator");
spriteRenderer = object.GetComponent(SpriteRenderer);
number = Random.Range(1,4);
if(number == 1) {
spriteRenderer.sprite = diamond;
}
else if(number == 2) {
spriteRenderer.sprite = circle;
}
else if (number == 3) {
spriteRenderer.sprite = triangle;
}
else {
spriteRenderer.sprite = square;
}
}
if(object.GetComponent(SpriteRenderer).sprite == circle) {
Debug.Log("Wrong Answer!");
Application.LoadLevel("GameOver");
}
if(object.GetComponent(SpriteRenderer).sprite == triangle) {
Debug.Log("Wrong Answer!");
Application.LoadLevel("GameOver");
}
if(object.GetComponent(SpriteRenderer).sprite == square) {
Debug.Log("Wrong Answer!");
Application.LoadLevel("GameOver");
}
if(Input.GetMouseButtonUp(0)) {
AcceptInput = true;
}
}
}
function YieldTestEnumerator () {
yield WaitforSeconds (0.5);
}
but it gives the following errors:
Assets/Scripts/GAME/buttons/Diamond.js(142,10): BCE0044: expecting (, found 'YieldTestEnumerator'.
Assets/Scripts/GAME/buttons/Diamond.js(142,32): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/GAME/buttons/Diamond.js(145,1): BCE0044: expecting }, found ''.
But I don't find anything wrong with this last bit:
function YieldTestEnumerator () {
yield WaitforSeconds (0.5);
}
All of the errors seem to be in that area. Do you have any ideas?
Are you showing the right script file? The error message indicates line 142 of a file named Diamond.js
, but you've only posted 74 lines of script.
Want to post the relevant portion of code?
Unexpected symbol is often due to the line before the error. Check for line endings, matched braces ect.
Answer by HarshadK · Aug 21, 2014 at 07:28 AM
You need to close your Update loop.
You need to put a closing bracket before the function YieldTestEnumerator () {
So it would become:
if(Input.GetMouseButtonUp(0)) {
AcceptInput = true;
}
}
}
}
Thank you so much! But then it gives me these errors:
Assets/Scripts/GA$$anonymous$$E/buttons/Diamond.js(36,16): BCE0019: 'sprite' is not a member of 'Object'.
and theres a whole bunch of them that is the same error. Do you know why?
Do not use 'object' as as a variable name since it is a reserved keyword.
Change the name of your Game Object to anything else than 'object'.
Actually, it didn't work. it still said the same error. What's wrong with this code? I changed to var anything : GameObject
never$$anonymous$$d it was because I had to change it to if(object.GetComponent(SpriteRenderer).sprite == diamond)
Your answer
![](https://koobas.hobune.stream/wayback/20220613161115im_/https://answers.unity.com/themes/thub/images/avi.jpg)