Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 shivamsingh22 · Aug 17, 2018 at 11:25 AM · 2drigidbody2dcollider2ddynamicistrigger

Why is my OnTriggerEnter2D(Collision2D other) function not working ?...

I've used Collider 2d in both the gameobject, Is trigger is also marked and used Rigidbody 2D in one of the gameobject and body type is also Dynamic, gravity is set to zero, But it's still not working I've checked everything is correct but it's still not working No "Warning" No "error" but it's still not working, Please, fellow programmers help me out, The Script I've written is mentioned below:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Powerup : MonoBehaviour {

 [SerializeField]
 private float _speed = 4.0f;

 // Update is called once per frame
 void Update () 
 {
     transform.Translate(Vector3.down * _speed * Time.deltaTime);    
 }

 void OnTriggerEnter2d(Collider2D other)
 {
     Debug.Log("Collided with: " + other.name);
     /* 
     if(other.tag == "Player" )
     {
         Player player = other.GetComponent<Player>();

         if(player != null)
         {
             player.canTripleFire = true;
         }

         Destroy(this.gameObject);
     } */        
 } 

}

Comment
Add comment · Show 1
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 Geejayz · Aug 17, 2018 at 11:31 AM 0
Share

Is the script attached to the object that the player is to collide with?

Does the Debug message appear in the Console?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Usama_S · Aug 17, 2018 at 11:53 AM

Change your method name to "OnTriggerEnter2D" and it will start working... Hopefully... :D ,This method is case sensitive and you have written "OnTriggerEnter2d" while the original one is with capitol "D" i.e "OnTriggerEnter2D"

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 Geejayz · Aug 17, 2018 at 12:17 PM 0
Share

Well spotted :)

avatar image
0

Answer by mohammadzeinallpuor · Aug 17, 2018 at 11:42 AM

your script have working for my.

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 mohammadzeinallpuor · Aug 17, 2018 at 11:47 AM 0
Share

i think your problem is for option Rigidbody .

avatar image
0

Answer by Ermiq · Aug 17, 2018 at 06:26 PM

Check the collision matrix in: upper-left corner of the screen -> Edit -> Project settings -> Physics2D. Then in the inspector look at the matrix and check if layers of your objects are set to collide with each other.

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

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

187 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 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 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 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 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 hits another but doesnt bounce off again. 0 Answers

Using child colliders with rigidbodies/joints in 2D 0 Answers

Is it possible to have continuous collision detection with dynamic points on Edge Colliders? 0 Answers

How to select the trigger layer on a Box Collider 2D 2 Answers

2D dynamic collider for dynamic shape 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