Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Issues with OnTriggerEnter2D

Discussion in 'Scripting' started by Yan_Yan_, Dec 5, 2015.

  1. Yan_Yan_

    Yan_Yan_

    Joined:
    Nov 14, 2015
    Posts:
    6
    Hi I'm new to using Unity and tried doing collision the original code below is what I tired So then I tried to just put the col.isTrigger by itself in the if statement it doesn't show anything in the console log Help would be greatly appreciated.
    public class jabTrigger :MonoBehaviour{
    publicint jabDamage =10;
    void onTriggerEnter2D(Collider2D col)
    {
    if(col.isTrigger !=true&& col.CompareTag("Enemy"))
    {
    col.SendMessageUpwards("underAttack", jabDamage);
    Debug.Log("collision");​
    }​
    }
    Enemy script

    voidUpdate(){
    if(currHealth <=0)
    {
    Destroy(gameObject);​
    }
    }
    publicvoid underAttack(int damage)
    {
    currHealth -= damage;
    Debug.Log(currHealth);​
    }​
    }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Yan_Yan_ and Deleted User like this.
  3. Yan_Yan_

    Yan_Yan_

    Joined:
    Nov 14, 2015
    Posts:
    6