Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question I am trying to activate lights everytime mu bullets hit my enemy

Discussion in 'Getting Started' started by devmaheswari2017, Sep 28, 2023.

  1. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    Heyy Everyone i am facing some issues with the point light, what i am trying to do is activating my point light every time my enemy got hit and create an good looking effects and i am trying to do that in c# as an gameobject, i am taking an gameobject refrence and "setActive" it to true but it's not working i tried debugging using messages and it everything was working fine but the light gameobject was not getting activated and idk why.

    Thanks for your help.
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,372
    what is your code to activate the light?
     
  3. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    private void Bleeding()
    {
    if (arrowThatHitMe != null)
    {
    Debug.Log("Arrow component has been found");
    Bullets bullet = arrowThatHitMe.GetComponent<Bullets>();
    if (bullet != null)
    {
    isbleeding = true;
    Debug.Log("Enemy bleeding effect is active");
    bleedinglighteffect.SetActive(true);
    }
    }
    }
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,372
    so depends where the heck you call that from, but if you're getting the debug logs, you must be calling it from somewhere, but are there any errors? cos if you get the debugs and not the light it implies bleedinglighteffect is null. but i would throw a nullreferenceexception
     
  5. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    Nahh there's no errors and it's not null also i have assigned the bleeding Effect prefab in the inspector but only thing that's different is there's animation on the light but i don't think that's matter as the whole gameobject itself is not getting activated
     
  6. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,372
    "whole game object itself"? are you trying to activate a child of a disabled object?
     
  7. miguel0l

    miguel0l

    Joined:
    Nov 10, 2021
    Posts:
    13
    i cant really tell based on what you've said so just get back to me when you have the time: your light is actually in the scene/on the game object right. if you're putting in a prefab of the light and not an actual light game object, you should use Instantiate(). Other than that, what bugfinders said is also possible, if you try to activate a child while its parent is still inactive, your child wont activate either
     
  8. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    Nahh the child object is activate all the time, I am trying to active the parent object
     
  9. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    yeah I didn't tried Instantiate() let me try and get back to you