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 /
avatar image
0
Question by igg · Aug 24, 2015 at 11:28 AM · errorerror messagecollider2dpacman

I'm building PacMan game by tutorial and getting error: `Property collider2D has been deprecated. Use GetComponent() instead.' But when I use GetComponent I get another error. What should I use instead?

public float speed = 0.4f; Vector2 destination = Vector2.zero;

 // Use this for initialization
 void Start () {
     destination = transform.position;
 }
 
 // Update is called once per frame
 void FixedUpdate () {
     Vector2 p = Vector2.MoveTowards (transform.position, destination, speed);
     GetComponent<Rigidbody2D> ().MovePosition (p);
     if ((Vector2)transform.position == destination) {
         if(Input.GetKey(KeyCode.UpArrow) && valid(Vector2.up))
             destination = (Vector2)transform.position + Vector2.up;
         if(Input.GetKey(KeyCode.DownArrow) && valid(-Vector2.up))
             destination = (Vector2)transform.position - Vector2.up;
         if(Input.GetKey(KeyCode.RightArrow) && valid(Vector2.right))
             destination = (Vector2)transform.position + Vector2.right;
         if(Input.GetKey(KeyCode.LeftArrow) && valid(-Vector2.right))
             destination = (Vector2)transform.position - Vector2.right;
     }
     Vector2 dir = destination - (Vector2)transform.position;
     GetComponent<Animator> ().SetFloat ("DirX", dir.x);
     GetComponent<Animator> ().SetFloat ("DirY", dir.y);
 }

 bool valid(Vector2 dir){
     Vector2 pos = transform.position;
     RaycastHit2D hit = Physics2D.Linecast (pos + dir, pos);
     return (hit.collider == collider2D);
 }

// I get error here: return (hit.collider == collider2D);

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
1
Best Answer

Answer by Blobbie · Sep 11, 2015 at 04:52 PM

Hi @igg,

As a noob myself, I am also currently following the noobtuts Pacman tutorial.

I fixed this by just following the error message from the console, which suggested to use GetComponent<Collider2D>(); instead. So I made it work by changing the line in question (28) to:

 return (hit.collider == GetComponent<Collider2D>());

I think this has something to do with an engine update that makes components from different classes less dependent on each other and thus speed up online players? I gathered that from this thread.

I also had to move the whole bool function up above FixedUpdate to make it work by the way.

I hope this helps. As I am learning, I come to appreciate reading through all of the line comments and error messages that fly across the screen, as they usually tell you into which direction to blindly poke ;)

Comment
Add comment · Show 2 · 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 igg · Sep 14, 2015 at 02:09 PM 0
Share

Thank you for your answer! I think you're completely right. I solved this problem simply by upgrading unity, and then it worked. Now I want to add more features in this game, like random movement of blinky objects. I tried lot of stuff but still doesn't work :/ If you are interested here's the link of question: http://answers.unity3d.com/questions/1038424/error-on-2d-random-movement.html

If you need help with something, ask freely, but yes I'm also noob.

avatar image drewbiedu · Oct 21, 2015 at 04:26 AM 0
Share

You fixed it! Haha thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Building WebGL compiles but when I open the webpage I get error occured of abort(-1) 0 Answers

Error, I have no idea why :( 2 Answers

Help please guys thank you so much! 1 Answer

Monodevelop Fatal Error 0 Answers

Could not find file "/Users/KingSloth/Desktop/Unity Files/Take those cars/Temp/StagingArea/Data/Native/build.asm.js 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