I Have my weapons set up and my animations working with mechanim, and i want to call an attack damage function inside the animation so that my attacks will line up with damage, but, I cant find in the animator where is says add animation event any functions.
This is my code of the melee script controlling the animations and melee damage.
Code:
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var DammageDelay : float = 0.6;
var TheAnimator : Animator;
var Playerstate : float;
private var Hit01Streak = 0;
private var Hit02Streak = 0;
function Update ()
{
PlayerStateController();
PlayerAnims();
}
function PlayerStateController ()
{
if (Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0)
{
if (Input.GetButton("Sprint"))
{
Playerstate = 2;
}
else
{
Playerstate = 1;
}
}
else
{
Playerstate = 0;
}
if (Input.GetButton("Fire1"))
{
Playerstate = 3;
}
}
function PlayerAnims ()
{
if (Playerstate == 0)
{
TheAnimator.SetBool("Sprinting", false);
TheAnimator.SetFloat("Playerstate", 0);
}
if (Playerstate == 1)
{
TheAnimator.SetBool("Sprinting", false);
TheAnimator.SetFloat("Playerstate", 1);
}
if (Playerstate == 2)
{
TheAnimator.SetBool("Sprinting", true);
TheAnimator.SetFloat("Playerstate", 2);
}
if (Playerstate == 3)
{
TheAnimator.SetFloat("Playerstate", 3);
if (Random.value >= 0.5 && Hit01Streak <= 2)
{
TheAnimator.SetBool("Hit01", true);
Hit01Streak += 1;
Hit02Streak = 0;
}
else
{
if (Hit02Streak <= 2)
{
TheAnimator.SetBool("Hit02", true);
Hit01Streak = 0;
Hit02Streak += 1;
}
else
{
TheAnimator.SetBool("Hit01", true);
Hit01Streak += 1;
Hit02Streak = 0;
}
}
yield WaitForSeconds(DammageDelay);
TheAnimator.SetBool("Hit01", false);
TheAnimator.SetBool("Hit02", false);
}
}
function AttackDammage ()
{
//Actual attacking
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
if (Physics.Raycast (ray, hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
Debug.Log("Hit");
}
}
}