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 mewtwodan8 · Aug 30, 2016 at 01:09 PM · animationcoroutinecollider2dcollision2dmessage

OnCollisionEnter2D message being ignored

THANKS IN ADVANCE!!!

Hi, I'm working on a 2D RPG much like the early final fantasy games and such. I'm relatively new to unity but i'm getting the hang of things. What i've been trying to do is settle warping between areas so walking out of a house or inbetween "rooms" of a forest or cave. The warping worked fine so i decided to add a fade, which also worked fine, the problem was when it faded, the player (who ive named anna in some cases) didnt stop moving so while the fade is happening you can still move aound, so i decided to change it from ontriggerenter2d to oncollisionenter2d. Im certain the exit points have been changed from triggers and there shouldn't be any errors in my script seeing as it worked fine when it was ontrigger but now the console gives me the error

"Script error: OnCollisionEnter2D This message parameter has to be of type: The message will be ignored"

Looking around on answers I've noticed that its supposed to actually state what type it should be of, but mine doesnt say, and its really bugging me.

These are all the scripts that use the fade or are affected by it: This is attached to the "collidable" game objects that represent the exits:

 public class Exit : MonoBehaviour {
 
     public AnnaController Player;
     public Rigidbody2D AnnaBody;
     public Transform PlayerLocation;
     public Transform UpDestination;
     public Transform DownDestination;
     public Transform RightDestination;
     public Transform LeftDestination;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     IEnumerator OnCollisionEnter2D(Collider2D other) {
         
         Fade sf = GameObject.FindGameObjectWithTag ("Fader").GetComponent<Fade> ();
 
         if (other.name == "Player") {
             yield return StartCoroutine (sf.FadeToBlack());
             if (Player.forwardVector == Vector2.up) {
                 PlayerLocation.position = UpDestination.position;
             }
             else if (Player.forwardVector == Vector2.down) {
                 PlayerLocation.position = DownDestination.position;
             }
             else if (Player.forwardVector == Vector2.right) {
                 PlayerLocation.position = RightDestination.position;
             }
             else if (Player.forwardVector == Vector2.left) {
                 PlayerLocation.position = LeftDestination.position;
             }
             yield return StartCoroutine (sf.FadeToClear());
         }
         
     }
 }


This script contains the coroutines for the fade (note that AnimationComplete has been set to run at the end of the fade animations): public class Fade : MonoBehaviour {

     private Animator anmtr;
     private bool isFading;
     public GameManager Manage;
 
     // Use this for initialization
     void Start () {
         anmtr = GetComponent<Animator> ();
     
     }
 
     public IEnumerator FadeToClear(){
         isFading = true;
         anmtr.SetTrigger ("FadeIn");
         Manage.gameRunning = false;
 
         while (isFading)
             yield return null;
     }
 
     public IEnumerator FadeToBlack(){
         isFading = true;
         anmtr.SetTrigger ("FadeOut");
         Manage.gameRunning = false;
 
         while (isFading)
             yield return null;
     }
     
     void AnimationComplete () {
         isFading = false;
         Manage.gameRunning = true;
     }
 }
 

This is the Game Manager Script which has a boolean value that determines whether the player can move or not: public class GameManager : MonoBehaviour {

     public bool gameRunning;
 
     // Use this for initialization
     void Start () {
     
         gameRunning = true;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

This is the player movement script: public class AnnaController : MonoBehaviour {

 public GameManager Manage;
 private Rigidbody2D rgdbdy;
 public Animator anmtr;
 private static bool playerExists;
 private float mSpeed;
 public bool overworld;
 public Vector2 forwardVector;
 public Vector2 mvmntVector;
 public bool Up;
 public bool Down;
 public bool Left;
 public bool Right;


 // Use this for initialization
 void Start () {
     anmtr = GetComponent<Animator> ();
     rgdbdy = GetComponent<Rigidbody2D> ();
     mSpeed = 0.75f;
     forwardVector = Vector2.zero;
     if (overworld) {
         if (!playerExists) {
             playerExists = true;
             DontDestroyOnLoad (transform.gameObject);

         } else { 
             Destroy (gameObject);
         } 
     }
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKey (KeyCode.B)) {
         mSpeed = 1.25f;
     } else {
         mSpeed = 0.5f;
     }

     if (Input.GetAxisRaw ("Horizontal") > 0.5f) {
         Right = true;
         Left = false;
         Up = false;
         Down = false;
     } else if (Input.GetAxisRaw ("Horizontal") < -0.5f) {
         Left = true;
         Right = false;
         Up = false;
         Down = false;
     } else if (Input.GetAxisRaw ("Vertical") > 0.5f) {
         Up = true;
         Left = false;
         Right = false;
         Down = false;
     } else if (Input.GetAxisRaw ("Vertical") < -0.5f) {
         Down = true;
         Left = false;
         Up = false;
         Right = false;
     }
         
     if (Right) {
         forwardVector = Vector2.right;
         //transform.Translate (new Vector3 (Input.GetAxisRaw ("Horizontal"), 0f, 0f));
         if (Manage.gameRunning) {
             rgdbdy.velocity = new Vector2 (Input.GetAxisRaw ("Horizontal") * mSpeed, 0f);
             anmtr.SetBool ("isWalking", true);
             anmtr.SetFloat ("inputX", 1f);
             anmtr.SetFloat ("inputY", 0f);
         }
     }
     if (Up) {
         forwardVector = Vector2.up;
         //transform.Translate (new Vector3 (Input.GetAxisRaw("Horizontal"), 0f, 0f));
         if(Manage.gameRunning) {
             rgdbdy.velocity = new Vector2 (0f, Input.GetAxisRaw ("Vertical") * mSpeed);
             anmtr.SetBool ("isWalking", true);
             anmtr.SetFloat ("inputX", 0f);
             anmtr.SetFloat ("inputY", 1f);
     }
 }
     if (Left) {
         forwardVector = Vector2.left;
         //transform.Translate (new Vector3 (0f, Input.GetAxisRaw("Vertical"), 0f));
         if (Manage.gameRunning) {
             rgdbdy.velocity = new Vector2 (Input.GetAxisRaw ("Horizontal") * mSpeed, 0f);
             anmtr.SetBool ("isWalking", true);
             anmtr.SetFloat ("inputX", -1f);
             anmtr.SetFloat ("inputY", 0f);
         }
     }
     if (Down) {
         forwardVector = Vector2.down;
         //transform.Translate (new Vector3 ( 0f, Input.GetAxisRaw("Vertical"), 0f));
         if (Manage.gameRunning) {
             rgdbdy.velocity = new Vector2 (0f, Input.GetAxisRaw ("Vertical") * mSpeed);
             anmtr.SetBool ("isWalking", true);
             anmtr.SetFloat ("inputX", 0f);
             anmtr.SetFloat ("inputY", -1f);
         }
     }
     if (Input.GetAxisRaw("Horizontal") == 0f && Input.GetAxisRaw("Vertical") == 0f) {
         rgdbdy.velocity = Vector2.zero;
         anmtr.SetBool ("isWalking", false);
     }

     

} }

If there's any thing you guys could do to point in the right direction pls, it would be much appreciated, Harambe be with you all!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Landern · Aug 30, 2016 at 01:12 PM

In your Exit.cs script, the type is incorrect in the method signature.

You have on line 20:

 IEnumerator OnCollisionEnter2D(Collider2D other) {

It should be a Collision2D type, the parameter name doesn't matter.

 IEnumerator OnCollisionEnter2D(Collision2D other) {

OnCollisionEnter2D Documentation which shows the corrected signature.

Comment
Add comment · Show 1 · 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 mewtwodan8 · Sep 02, 2016 at 12:40 PM 0
Share

Hi, Thanks for replying, i've tried your solution and it has removed the error i was given but now another error has shown up saying "Type 'UnityEngine.Collision2D' does not contain a definition for 'name' and no extension method 'name' of type 'UnityEngine.Collision2D could be found (are you missing a using directive or assembly reference?)'" Do you by any chance know whats going on? I'd appreciate any tips or anything Thanks :P

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Collision not working 1 Answer

2d balls stuck in box colliders 1 Answer

using coroutines 1 Answer

Audio Issues with Animation + Grounded 0 Answers

Destroy Problem 2 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