Sign in to follow this  
StayFly

Two Errors With my code

Recommended Posts

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

[CODE]
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)
}

}
[/CODE]

If this isn't enough information please feel free to ask me below and I will provide more. Thank you for your help [img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sweet I got it working on line 86 I had to remove transform.position.y

Thanks
[b] [url="http://www.gamedev.net/user/181063-bacterius/"]Bacterius[/url] and [url="http://www.gamedev.net/user/78572-rip-off/"]rip-off[/url][/b]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this