Unexpected symbol `void' in class, struct, or interface member declaration
Hi, I am making a 2D infinite runner, and I am having this problem on this script:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UnityStandardAssets._2D
{
public class Restarter : MonoBehaviour
{
bool CanMove = true;
bool MoveWait=false;
public IEnumerator
void OnCollissionEnter2D(Collision col1){ERROR HERE: Unexpected symbol `void' in class, struct...
if (col1.gameObject.tag == "Enemy") {
GetComponent<Animation> ().Play ("RedGiantDEATHTOALL");
CanMove = false;
if (!MoveWait)
StartCoRoutine (WaitToMove ());
}
}
IEnumerator MoveToWait() {
MoveWait=true;
yield return new WaitForSeconds(1.5f); //Change to Animation Duration
MoveWait=false;
CanMove=true;
}
}
}
I don't know how to fix it. Can someone help me?
I also don't know how to make the IEnumerator public.
Thanks for your help!
Answer by Addie · Apr 18, 2016 at 08:00 PM
@Ejpj123 use the animator and make both animations use root motion, also only animate the root parent game objects position and the child gameobject animate its rotation.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public Animator anim;
public Collider2D playerCol;
public Rigidbody2D rb;
public int hashDie;
void Start ()
{
playerCol = GetComponentInChildren<Collider2D>();
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
hashDie = Animator.StringToHash("Base Layer.Die");
}
void Update ()
{
}
public void OnCollisionEnter2D(Collision2D col)
{
if(col.collider.tag == "Enemy")
{
playerCol.enabled = false;
rb.gravityScale = 1;
anim.Play(hashDie);
}
}
}
When I tested it out, add the play animation on the oncollison void, and nothing worked. Ins$$anonymous$$d I stopped moving every time I jumped. Am I supposed to put the play Animation, on the IEnumerator void ins$$anonymous$$d?
When my player collides with an enemy, I want my player to stop moving (which is in a separate script), and I want the player to play a death animation.
are you using the legacy animation not the animator
I am using legacy. I just tried it without legacy and added the animation on the animator and still nothing worked.
Your answer
Follow this Question
Related Questions
Help me fix my code!! 1 Answer
"void" error in SceneManager Script 1 Answer
C# - Error " does not implement interface member" 2 Answers
Unexpected symbol `void' 0 Answers
Void cannot be used in this context, unexpected symbol expecting `,', `;', 0 Answers