Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question