Two Errors With my code

Started by
3 comments, last by StayFly 11 years, 12 months ago
Hello,

I am following along with this tutorial making a simple 2d Shooter. However I have came across a problem in my code. I am really new to programming I have never done it before. This is my first game where I am using scripts. so I am getting two errors.

First Error
Line(121,9): CS1525 Unexpected Symbol '}'

Second Error
Line(124,1): CS8025 Parsing Error


using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
//Playing
//Explosion
//Invincible

enum State
{
Playing,
Explosion,
Invincible
}

private State state = State.Playing;

public float PlayerSpeed;

public GameObject ProjectilePrefab;
public GameObject ExplosionPrefab;

public static int KillCount = 0;
public static int Lives = 3;

private float ProjectileOffSet = 1.2f;
private float shipInvisibleTime = 1.5f;
private float shipMoveOnToScreenSpeed = 5;
private float blinkRate = .1f;
private int numberOfTimesToBlink = 10;
private int blinkCount;

// Update is called once per frame
void Update ()
{
if (state != State.Explosion)
{
//Amount to move
float amtToMove = Input.GetAxisRaw("Horizontal") * PlayerSpeed * Time.deltaTime;

// Move the player
transform.Translate(Vector3.right * amtToMove);

// ScreenWrap
if (transform.position.x <= -13.5f)
transform.position = new Vector3(13.4f, transform.position.y, transform.position.z);
else if (transform.position.x >= 13.5f)
transform.position = new Vector3(-13.4f, transform.position.y, transform.position.z);

if(Input.GetKeyDown("space"))
{
//Fire projectile
Vector3 position = new Vector3(transform.position.x, transform.position.y + transform.localScale.y / 2);
Instantiate(ProjectilePrefab, position, Quaternion.identity);

}
}
}

void OnGUI()
{
GUI.Label(new Rect(10, 10, 10000, 20), "Kill Count: " + Player.KillCount.ToString());
GUI.Label(new Rect(10, 30, 60, 20), "Lives: " + Player.Lives.ToString());
}


void OnTriggerEnter(Collider otherObject)
{
if (otherObject.tag == "Enemy" && state == State.Playing)
{
Player.Lives--;

Enemy enemy =(Enemy)otherObject.gameObject.GetComponent("Enemy");
enemy.SetPositionAndSpeed();

StartCoroutine(DestroyShip());
}
}

IEnumerator DestroyShip()
{
state = State.Explosion;
Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
gameObject.renderer.enabled = false;
transform.position = new Vector3(0f, -5.0f, transform.position.y, transform.position.z);
yield return new WaitForSeconds(shipInvisibleTime);
if (Player.Lives > 0)
{
gameObject.renderer.enabled = true;

while (transform.position.y < -2.8)
{
// Move the ship up
float amtToMove = shipMoveOnToScreenSpeed * Time.deltaTime;
transform.position = new Vector3(0f, transform.position.y + amtToMove, transform.position.z);

yield return 0;
}

state = State.Invincible;

while (blinkCount < numberOfTimesToBlink)
{
gameObject.renderer.enabled = !gameObject.renderer.enabled;

if (gameObject.renderer.enabled == true)
blinkCount++;

yield return new WaitForSeconds(blinkRate);
}
blinkCount = 0;
state = State.Playing;



}
else
Application.LoadLevel(2)
}

}


If this isn't enough information please feel free to ask me below and I will provide more. Thank you for your help cool.png
Advertisement
There is no line 121 or line 124 in the code snippet you posted (it stops at line 120). Did you trim/reformat it before posting (or does the site's code formatter do it automatically)?

You are missing a semicolon on the last line of code.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

a semicolon at the end of Application.LoadLevel(2); fixes the problem but it gives me another error (86,104): error CS1729:The type 'unityEngine.Vector3' Does not contain a constructor that takes '4' arguments
Text is the best representation of text. We cannot copy and paste images into our IDEs (usefully).
Sweet I got it working on line 86 I had to remove transform.position.y

Thanks
Bacterius and rip-off

This topic is closed to new replies.

Advertisement