Animation Event Script

Please, i need help with a question:

StartSinkin Script
```csharp
*using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StartSinkin : MonoBehaviour {

bool isSinking;
private SpriteRenderer enemy;
// Use this for initialization
void Awake () {

    enemy = GetComponent<SpriteRenderer>();

    Startsinkin(enemy); //im not sure of how make the call here, help pls!!!
}

// Update is called once per frame
public void Startsinking()

{

    GetComponent<Rigidbody>().isKinematic = true;
    isSinking = true;
    //ScoreManager.score += scoreValue

    Destroy(gameObject, 2f);

}

}*
* *Health Script* *csharp
*using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour {

public int hp;
public int currentLife;
public float sinkSpeed;
public int scoreValue;
public AudioClip deathClip;

Animator anim;
AudioSource enemyAudio;
ParticleSystem hitParticles;
CapsuleCollider capsuleCollider;
bool isDead;
bool isSinking;
// Use this for initialization
void Awake () {

    anim = GetComponent<Animator>();
    enemyAudio = GetComponent<AudioSource>();
    hitParticles = GetComponentInChildren<ParticleSystem>();
    capsuleCollider = GetComponent<CapsuleCollider>();

    currentLife = hp;

}

// Update is called once per frame
void Update () {

    if (isSinking)
    {
        transform.Translate(-Vector3.up * sinkSpeed * Time.deltaTime);


        TakeDamage(); // i dont know either how to to this method call
    }

}


public void TakeDamage (int amount, Vector3 hitPoint)
{
    if (isDead)
        return;

    enemyAudio.Play();

    hitParticles.transform.position = hitPoint;
    hitParticles.Play();

    if (currentLife <= 0)
    {
        Death();
    }
}

void Death ()
{
    isDead = true;

    capsuleCollider.isTrigger = true;

    anim.SetTrigger("Dead");

    enemyAudio.clip = deathClip;
    enemyAudio.Play();
}

}*
```
I is the right way to add a script to an animation?
and how can i get right the methods calls?
pls i need help with this, just to frustating XD, thanks!
Related Links:
Survival Shooter Training Day Phases - Unity Learn
https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

It is hard to tell exactly what you are asking about. You havent explained what is currently happening and what you intend to happen.

Well, im trying to get a damage system, where the enemys can take damage and can die.
The second one is a script 4 the health system, and the first one is an script atached to the die animation, so the scripts happens when the caracter plays the dies animation . And it trys to interact them both (scripts) to do that.

In fact its pretty clear, i think what the codes try to do.

the related links sends you to the source from i “have taken” the code

This is all in all very confusing…I will try to help you but your question is very unclear. I have some questions:

    void Awake () {
        enemy = GetComponent<SpriteRenderer>();
        Startsinkin(enemy); //Why are you calling Startsinking on Awake? Do you want your ship to sink straight away?
    }
    public void Startsinking()//The previously called function takes a spriteRenderer enemy...Why is this empty?
    {
        GetComponent<Rigidbody>().isKinematic = true;
        isSinking = true;
        //ScoreManager.score += scoreValue
        Destroy(gameObject, 2f);
    }
    void Update () {
        if (isSinking)
        {
            transform.Translate(-Vector3.up * sinkSpeed * Time.deltaTime);
            TakeDamage(); // should this be in the Update? Are you trying to apply damage to it every frame that isSinking is true?
        }
    }

If I understood correctly you are trying to have a script execute at a specific time in an animation? If so the link you provided:
https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html
explains how to do this step by step

Well, thats the thing, im not really sure, of how to do, cause im taking the code from a isometric 3d shooter game, and im trying to put at a 2d shooter, so, all i know right now is that im not pretty sure of how to do the things, i dont know, caus i was trying to do, but im not pretty sure if use a call from the sprite renderer is the right way to make sink the player, maybe ill just play the death animation and forger about that part.

About the isSinkin, you are damn right, maybe shall i put there the death call method, but i guess that i fucked up or something, cause the void TakeDamage have included at it a call of the death method.
i have “taken” the code, from the first link that i hav putted at the end of my first post, ill try to get work it, with the things that we have say, but if u mind to ger something that could help, pls, im all ears. :slight_smile:

And about the first question, its cause its a script taht its atached to the animation, so it will play itself at the moment that death animation is played.

For example, another thing that i need to know, its what i sall put instead de capsulle collider