P
P
progerstas2020-06-08 21:13:22
C++ / C#
progerstas, 2020-06-08 21:13:22

Where is my mistake in the code?

Please help, I can't find what the problem is, like all the brackets are in place
Error: Assets\scripts\ExploteCubes.cs(20,1): error CS1022: Type or namespace definition, or end-of-file expected

Code:

using UnityEngine;

public class ExploteCubes : MonoBehaviour {

  private bool _collisionSet;

  private void OnCollisionEnter(Collision collision) {
    if(collision.gameObject.tag == "Cube" && !_collisionSet) {
      for(private int i = collision.transform.childCount-1; i >= 0; i--) {
        Transform child = collision.transform.GetChild(i);
        child.gameObject.AddComponent<Rigidbody>();
        child.gameObject.GetComponent<Rigidbody>().AddExplosionForce(70f, Vector3.up, 5f);
        child.SetParent(null);
      }
      Destroy(collision.gameObject);
      _collisionSet = true;
    }
  }

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-06-08
@progerstas

What for for(private int i?

T
telonily, 2020-06-08
@telonily

Try adding your code after using in namespace:

using UnityEngine;
namespace Game {
   public class ExploteCubes...
   ...
   ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question