i have one enemy and one char.
the sword of my char has one script
(DanoDaEspada)
#pragma strict
function OnCollisionEnter(Player:Collision){
if(Player.gameObject.tag=="AI"){
AIlife.aihp-=5;
}
}
and in my enemy i have other script
#pragma strict
static var aihp:float;
var aidif:float;
function Start () {
}
function Update () {
if(aidif == 1){
aihp=10;
if(aihp<1){
Dead();
Attributes.xp+=10;
}
}
if(aidif == 2){
aihp=30;
if(aihp<1){
Dead();
Attributes.xp+=20;
}
}
}
function Dead(){
Destroy(gameObject);
}
please help me.
if i start the animation attack, the sword collide with my enemy but he doesnt die!
whats the problem?
Right off the bat, you’re using floats to store whole number data- if you use ints then it’ll make whole-number comparisons like this a lot more predictable.
Second, you’re setting the values of the data right before checking the values for “< 1” and they’ll never be less than 1 in that situation. Assign aihp = 30 in the Start() function, or initialize them to default values in the definition.
Third, aihp shouldn’t be static, because then it’s going to be the same for every enemy in the game (static means it belongs to the class as a whole, not the current “instance” of the class).
Fourth, you should place the Attributes exp increase before the call the function to destroy the current object- for form’s sake if nothing else.
now thats code is ok?
i delete danodaespada
and the colision script damage has been moved for that
/////////////////////////////////////////////////////////////////////////////
function OnCollisionEnter(Player:Collision){
if(Player.gameObject.tag==“sword”){
aihp-=5;
////////////////////////////////////////////////////////////////////////////////
#pragma strict
var aihp:float;
var aidif:float;
function Start () {
aihp=30;
}
function Update () {
if(aidif == 1){
aihp=10;
if(aihp<1){
Attributes.xp+=20;
Dead();
}
}
if(aidif == 2){
aihp=30;
if(aihp<1){
Attributes.xp+=20;
Dead();
}
}
}
function Dead(){
Destroy(gameObject);
}
function OnCollisionEnter(Player:Collision){
if(Player.gameObject.tag=="sword"){
aihp-=5;
}
}
but again my enemy doesnt die!
can you create a other script for me?
Like this:
#pragma strict
var aihp:int;
var aidif:int;
function Start ()
{
if(aidif == 1)
aihp = 10;
else
aihp = 30;
}
function Update ()
{
if(aihp < 1)
{
Attributes.xp += 20;
Dead();
}
}
function Dead()
{
Destroy(gameObject);
}
function OnCollisionEnter(Player:Collision)
{
if(Player.gameObject.tag == "sword")
{
aihp -= 5;
}
}