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. Dismiss Notice

Question I need help for a basic problem because I'm a noob :(

Discussion in 'Getting Started' started by Florion111, Jul 26, 2023.

  1. Florion111

    Florion111

    Joined:
    Jul 25, 2023
    Posts:
    7
    I need help, please
    .
    I got a script (on a gameObject) which can do an effect for "TakeDamageNight(20);"
    upload_2023-7-26_10-24-54.png
    , and another script (on a prefab of another gameObject) from where I wanna originate the "TakeDamageNight(20);"
    upload_2023-7-26_10-25-39.png
    But I didnt manage to connect the two with instructions given on internet!
    .
    Another can help me?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Code (CSharp):
    1. collision.GetComponent<HealthNight>().TakeDamageNight(20);
    That is only the code issue. Take a look at OnTriggerEnter2D to make sure everything else is setup.

    Plus, you could easily find plenty of examples of OnTriggerEnter2D being used to get the needed component and what your object actually hit.
     
    AngryProgrammer and Florion111 like this.
  3. Florion111

    Florion111

    Joined:
    Jul 25, 2023
    Posts:
    7
    ... That worked!
    Thank you!
     
    AngryProgrammer likes this.