In unity I have my main weapon which is an axe this axe has all the animation set to it.
I found a zombie on the internet which came with a script how can i make it that when my axe hits the zombie it will do damage to it.
This is the zombie script:
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
var isNotDead : boolean = true;
var health : float = 100;
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
if(health < 1){
isNotDead = false;
animation.Play("die");
Destroy(gameObject, 1);
}
if(isNotDead){
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
var distance = Vector3.Distance(target.position, myTransform.position);
if (distance < 3.0f) {
animation.Play("attack1");
}
else{
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
animation.Play("walk1");
}
}
}
function ApplyDamage(dmg : float){
health -= dmg;
}
Can someone please post a script that i need to add to my axe. Also I need some help giving my player health. Thanks
ps sorry for bad english.
you can create a raycast with the range of your Axe an fire the raycast when you press the Axe button
I will try create the script (I need this script two).
você pode criar um raycast com a gama de seu machado um fogo a raycast quando você pressiona o botão de Machado.
I will try create the script (I need this script two).
you can create a raycast with the range of your Axe an fire the raycast when you press the Axe button.
I will try create the script (I need this script two).
you can create a raycast with the range of your Axe an fire the raycast when you press the Here is the Script:
var Range = 5.0;
var Axe : GameObject;
var AttackAnimName = "AnimName";
var damage = 5;
function axeRayShoot () {
var Hit : RaycastHit;
var DirectionRay = transform.forward;
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position, DirectionRay, Hit, Range))
{
Axe.animation.Play(AttackAnimName);
if(Hit.transform.tag == "Enemy")
{
Hit.collider.GetComponent(Zombie).health = Hit.collider.GetComponent(Zombie).health - damage;
}
}
}
function Update () {
if(Input.GetButtonDown("Fire1")){
axeRayShoot ();
}
}
you can create a raycast with the range of your Axe an fire the raycast when you press the Axe Button.
Here is the Script:
var Range = 5.0;
var Axe : GameObject;
var AttackAnimName = "AnimName";
var damage = 5;
function axeRayShoot () {
var Hit : RaycastHit;
var DirectionRay = transform.forward;
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position, DirectionRay, Hit, Range))
{
Axe.animation.Play(AttackAnimName);
if(Hit.transform.tag == "Enemy")
{
Hit.collider.GetComponent(Zombie).health = Hit.collider.GetComponent(Zombie).health - damage;
}
}
}
function Update () {
if(Input.GetButtonDown("Fire1")){
axeRayShoot ();
}
}