Unexpected symbol 'int'. (S05L80)

Edit: I ended up deleting the script and removing it from the bricks I had created and just remade the script the exact same way I had the first time. I have a feeling when I wrote in “public int” it automatically assumed I wanted “public interface” which I had to backspace to correct. That may have effected it in some way, i’m unaware, other than that… Magic.

I’m finding an issue with declaring a public int. I’m getting an error asking for a public class, delegate, enum, etc. for both 'timesHit; and “maxHits;”. I’ve taken a look around and cannot seem to find the answer to this one. I am using Visual.

// error log that’s showing in console:
Assets/Scripts/Brick.cs(5,7): error CS1525: Unexpected symbol int', expectingclass’, delegate',enum’, interface',partial’, or `struct’

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

 public int timesHit;
 public int maxHits;

 public class Brick : MonoBehaviour {

// Use this for initialization
void Start () {
    timesHit = 0;
}

// Update is called once per frame
void Update () {
	
}

void OnCollisionEnter2D (Collision2D col) {
    timesHit++;
}

Hi,

You need to put those class level variables inside the class definition, currently they are outside of it.

using UnityEngine;

public class Brick : MonoBehaviour {

    public int timesHit;
    public int maxHits;

    // ...
}

Hope this helps :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms