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

Triggering a death animation (Script needed)

Discussion in 'Scripting' started by chaosrecordsuk, Aug 26, 2018.

  1. chaosrecordsuk

    chaosrecordsuk

    Joined:
    Aug 15, 2018
    Posts:
    8
    Hello!

    So I have a bunch of npc animations cycling through on a loop. I also have a death animation inside the animator controller but it's not attached to anything. My asset characteris called "PsychoZombie" *Not another zombie game :)* Anyway could one of you kind community members write me a script that will trigger the death animation when the zombie is shot. Also you might have to code me a raycast as my game so far has no way of knowing of how to shoot a gun. I know this is a big ask but it would help. I must have watched countless videos on how to do this and when it comes to the coding part it either doesn't work or it is to long winded. I am currently learning C#. Thx for any help or advise offered. Cheers! :)
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    The community doesn't shine kindly on code begging.

    Instead we prefer to assist people in figuring out how to do things.

    If you want someone to write it for you, head on over to the Unity Connect and post a job listing (preferably paid, though you might find people who do it for free).
    https://connect.unity.com/

    ...

    If instead you're willing to put in the effort yourself. Well then we're going to need to see what you have currently, what effort you've put in up to this point, what your animator looks like, and what specifically about it has you hung up.

    Maybe show us your brainstorm on how you think it should be accomplished, and we'll help point out where your on the right path, and where you're not.

    For starter material you might want to look into things like:
    Animator Parameters (specifically the 'trigger'):
    https://docs.unity3d.com/Manual/AnimationParameters.html

    The documentation on how 'SetTrigger' works:
    https://docs.unity3d.com/ScriptReference/Animator.SetTrigger.html

    And any number of tutorials on guns:
    Google - "unity gun raycast tutorial"
     
    durukanozanalp, MisterSkitz and eses like this.
  3. chaosrecordsuk

    chaosrecordsuk

    Joined:
    Aug 15, 2018
    Posts:
    8
    Sorry if it seemed I was begging. I don't know the protocol here. I'm new so forgive me. I must have watched what feels like every video on youtube about setting up raycast and there code doesn't work for me! :( Thx anyway I'll be sure to check it out!
     
  4. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    What's your code looking like?

    Anyway, there's quite a few different ways you grab game objects.

    public GameObject animObject;

    getComponent<GameObject>();


    You can summon death scene by creating a function, for example void DeadAF() and setting some simple logic if(health <= 0) BOOM! DeadAF();
     
  5. durukanozanalp

    durukanozanalp

    Joined:
    Jan 4, 2019
    Posts:
    12