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

warning CS0642: Possible mistaken empty statement

Discussion in 'Scripting' started by timSMMsirolF, Jul 19, 2022.

Thread Status:
Not open for further replies.
  1. timSMMsirolF

    timSMMsirolF

    Joined:
    Jul 19, 2022
    Posts:
    1
    I tried to follow Brackeys tutorials but it didn't go so well. I now get the message:
    "Assets\PlayerCollision.cs(8.54): warning CS0642: Possible mistaken empty statement"
    What does this mean and how can I improve my code?
    This is my code:

    using UnityEngine;
    public class PlayerCollision : MonoBehaviour
    {
    void OnCollisionEnter(Collision collisionInfo)
    {
    if(collisionInfo.collider.name == "Obstacle");
    {
    Debug.Log("We hit an obstacle!");
    }
    }
    }

    I tried to let the console say "we hit an obstacle" when the player hits an obstacle but now it also says that the player hits an obstacle when it actualy hits the ground!
    How do i fix this?
    I hope someone knows the answer to my question.
    Thank you.
     
    Last edited: Jul 19, 2022
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Remove the ; character at the end of line 8. The error is actually 8,54 , the first number is the line number. Please post here with code tags in the future, look at a few other posts first to see how the code is formatted.

    if(collisionInfo.collider.name == "Obstacle");
     
  3. SpammerX

    SpammerX

    Joined:
    Apr 27, 2014
    Posts:
    3
    I also require help with my code I am fairly new. Is this ok anyway to simplify this?

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

    public class DestroyOutOfBounds : MonoBehaviour
    { private float topBound = 30;

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

    Destroy(gameObject);
    }



    }
    }
     
  4. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    If you have a question that isn't related to the original post, you should create a new thread to ask your question, rather than posting in the unrelated one.

    Make sure to use code tags.

    but, I can tell you that this sounds pretty reasonable to me :) . You check once per update if some simple condition has been met; you can't do much better than that.
     
Thread Status:
Not open for further replies.