Need help with making disappearing platforms. Error CS1525
Im new to unity and scripting in general. Im trying to make a platform disappear after 2 seconds when my character touches it but Im getting error CS1525 Unexpected symbol on the line that says IEnumerator Destroy() { Ive tried to fix it but I can't seem to figure it out
Here is my Code
using UnityEngine;
using System.Collections;
public class breakingFloor : MonoBehaviour {
public float Seconds = 2;
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "Character") {
Destroy();
}
IEnumerator Destroy() {
yield return new WaitForSeconds(Seconds);
Destroy(gameObject);
}
}
Answer by OncaLupe · Nov 15, 2015 at 07:39 AM
Generally Unexpected Symbol means Unity came across something that doesn't belong. Usually it's a missing semicolon, or missing/extra curly braces.
In this case, look closer at the OnTriggerEnter2D method. You have one open curly brace, then an If() with a second open curly brace, then after the Destroy you have one closing curly brace. Then it hits a new method before all matching curly braces have been closed. You need to either add another closing curly brace, or remove the one on the line with the If.
Also, Destroy is a built in method in Unity, you might want to rename your Destroy method to avoid confusion.