Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed May 23, 2014 at 06:27 AM by Fattie for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by nmkaitogames · May 22, 2014 at 10:00 PM · collisionfloatcollision2dsetworking

animation not playing on collision2d

Hello, I had this code working, and then unity crashed, and even though everything had been saved multiple times before that, it got rid of all my work, luckily I still had the code, so I rebuilt the project and now this code won't work. I tried everything and still can't figure it out, it has to do with the collision 2d function which is at the very end, but I will include the whole code for reference: Thank you soo much, any help is appreciated!

 private var ray: Ray;
 private var rayCastHit: RaycastHit;
 var animator: Animator;
 function Start () {
 animator = GetComponent("Animator");
 
 }
 
 function Update(){
 
 transform.position.y += .05;
 if(Input.GetMouseButton(0)){
 
 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
 
 if(Physics.Raycast(ray, rayCastHit)){
 
 if(rayCastHit.collider.gameObject.tag == "leftbottom"){
 transform.position.x -= .05;
 transform.position.y -= .07;
 animator.SetBool("isright", false); 
 animator.SetBool("isleft", false); 
 }
 
 if(rayCastHit.collider.gameObject.tag == "leftmiddle"){
 transform.position.x -= .05;
 transform.position.y += .02;
 animator.SetBool("isright", false);
 animator.SetBool("isleft", true); 
 }
 if(rayCastHit.collider.gameObject.tag == "lefttop"){
 transform.position.x -= .05;
 transform.position.y += .03;
 animator.SetBool("isright", false);
  animator.SetBool("isleft", true);
 }
 if(rayCastHit.collider.gameObject.tag == "rightbottom"){
 transform.position.x += .05;
 transform.position.y -= .07;
 animator.SetBool("isright", false);
 animator.SetBool("isleft", false); 
 }
 if(rayCastHit.collider.gameObject.tag == "rightmiddle"){
 transform.position.x += .05;
 transform.position.y += .02;
 animator.SetBool("isleft", false); 
  animator.SetBool("isright", true); 
  }
  if(rayCastHit.collider.gameObject.tag == "righttop"){
 transform.position.x += .05;
 transform.position.y += .03;
 animator.SetBool("isleft", false); 
 animator.SetBool("isright", true); 
 }
 }
 }
 
 
 }
 
 function OnCollisionEnter2D(coll: Collision2D) {
 if (coll.gameObject.tag == "asteroid"){
     numOfHits += 1.0;
 animator.SetFloat("hits", numOfHits);
 }
 }
Comment
Add comment · Show 5
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 ozone · May 23, 2014 at 12:04 AM 0
Share

Would you please describe exactly what result the code is supposed to produce and what result it currently produces?

avatar image nmkaitogames · May 23, 2014 at 01:30 AM 0
Share

Yes it is supposed to play a "hits" animation which is the damaged ship, and now , even though i see the float increase, the animation doesnt transition from the movement to the damaged animation.

avatar image PippyLongbeard · May 23, 2014 at 01:53 AM 0
Share

This is most likely a problem with your Animator setup. If you could post a picture of it, that'd be really helpful in identifying your problem.

avatar image PushpaK · May 23, 2014 at 05:58 AM 0
Share

Check your animator controller for any missing thing. I got same problem with OnCollisionEnter2D(). If you mark rigidbody to is$$anonymous$$inematic sometimes function doesn't get called.

avatar image nmkaitogames · May 24, 2014 at 01:16 PM 0
Share

Honestly, the problem got solved by me deleting the transitions as they were from clip to clip, and recreating them the exact same. I have no clue what the problem was, probably just one of those Unity quirks, thanks a ton!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Object passes through collider even when isTrigger is turned off. 2 Answers

OnTriggerEnter2D working, OnColliderEnter2D not working 1 Answer

2D Isometric Rigid Body Collision Resolution (collide and side) Not working 0 Answers

OnCollisionEnter2D doesn't work every time. 1 Answer

Object passes through collider even when isTrigger is turned off. 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