Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question CS0642: possible mistaken empty statement

Discussion in 'Scripting' started by SpammerX, Dec 29, 2022.

  1. SpammerX

    SpammerX

    Joined:
    Apr 27, 2014
    Posts:
    3
    Hello guys I'm fairly new. I had received this error while doing the step by step tutorial. Can anyone help me understand? (16,45)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DestroyOutOfBounds : MonoBehaviour
    { private float topBound = 30;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    if (transform.position.z > topBound);
    { Destroy(gameObject);

    }

    }
    }

    I'm still new sorry.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,148
    Just a typo, your if statement has a ; at the end of it. Remove it.
     
    SpammerX likes this.
  3. TzuriTeshuba

    TzuriTeshuba

    Joined:
    Aug 6, 2019
    Posts:
    185
    Code (CSharp):
    1. if (transform.position.z > topBound);
    should not have a semicolon.
    Please use code tags when placing code in your post. Its also helpful when you provide more info on your issue. you only have 2 lines so it jumps out. I know you're new, so just letting you.

    Also, read the compile errors messages and try to make sense of them.
    (16,45) means the 45th character on line 16 is where your issue is, and it probably mentioned the semicolon. Even veterans make these typos, but catch them instantly just because the compiler yells at them.
     
    chemicalcrux and SpammerX like this.
  4. SpammerX

    SpammerX

    Joined:
    Apr 27, 2014
    Posts:
    3

    Thank you I didn't realize this. also I never knew what the numbers mean just that it was there now I know.
     
    chemicalcrux likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,946
    Here's the cribsheet:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.