Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Ejpj123 · Apr 18, 2016 at 04:55 PM · interfacesimplevoidunexpected-symbolmember

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Addie · Apr 18, 2016 at 05:06 PM 0
Share

@Ejpj123 Void OnCollisionEnter2D should have one S.

avatar image Ejpj123 · Apr 18, 2016 at 06:36 PM 0
Share

It still has the problem:

alt text

screenshot-2016-04-18-132721.png (80.7 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
     }
 }

}

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ejpj123 · Apr 18, 2016 at 11:17 PM 0
Share

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?

avatar image Addie Ejpj123 · Apr 19, 2016 at 01:04 AM 0
Share

what do you want this script to do exactly

avatar image Ejpj123 · Apr 19, 2016 at 02:05 AM 0
Share

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.

avatar image Addie Ejpj123 · Apr 19, 2016 at 02:11 AM 0
Share

are you using the legacy animation not the animator

avatar image Ejpj123 Addie · Apr 20, 2016 at 02:43 AM 0
Share

I am using legacy. I just tried it without legacy and added the animation on the animator and still nothing worked.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

41 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges