Damage trigger?

I am trying to make the ai have an invisably box infront of them and when i am in side the tigger box i will loose 10 hp a second? i cant find any tutorials or scripts to do this EXACTLY i cant come up with scripts on my own i have been tring to modify ones i find on the internet and other together but no matter how i put it it desnt work can someone post a script that would be VERY Simple to modify or needs no modifications at all?

I have done it after many many test and tests i have made the script work thanks!!

1 Answer

1
function OnCollisionEnter(collision : Collision) {
    if(collision.gameObject.tag == Player){
        collision.gameObject.//Whatever you want to edit on the player...  Get their component and change what you need, anything...
    }

}

This'll work if you make the AI have a larger collider, then this'll run, and you can edit whatever is needed...

Read this page for what kind of things you can do: http://unity3d.com/support/documentation/ScriptReference/GameObject.html

But what do i add to make it apply damagewould i put after the last period "if (player) { player.ApplyDamage(10000); }"

i understand what you mean but i don know how to right scripts just i can kind of recognize some parts and modify them so i cant really and the whole apply damage and time.time.

I've been using unity a week so don't take my word for granted and correct me if im wrong, but I would set two vars.. var damage = 10 Private var health.Health /* I have a 'Health' script on my player model that determines it's current welfare with a static var */ //then you can say if(collision.gameObject.tag == Player){health =- damage} //to damage the player's health by however much you have set the damage variable. I have also just noticed I am a month late not a day late.. it is not april anymore..