Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Trigger a function only when a certain event happens

Discussion in 'Scripting' started by S4MA3L, Jul 28, 2020.

  1. S4MA3L

    S4MA3L

    Joined:
    Apr 17, 2020
    Posts:
    38
    I am trying to develop a unity pun2 multiplayer, and I have a problem with applying damage when a projectile explodes in range of the player. So my question is.. All network stuff apart.

    How can I trigger a function inside my player GameObject when the explode function inside my throwable projectile GameObject is triggered? These are separate gameobjects.
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You could Spherecast and check for any players within it and call the method on the ones that are.
     
  3. S4MA3L

    S4MA3L

    Joined:
    Apr 17, 2020
    Posts:
    38
    I already thought of that. But I set a timer for the throwable projectile for explosion. I only want this script to be called when the explosion happens after the fixed time. That's what confuses me.
     
  4. Flynn_Prime

    Flynn_Prime

    Joined:
    Apr 26, 2017
    Posts:
    387
    If you already have the timer then just do as the above post mentioned once the timer has elapsed.