- Home /
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!!
Answer by Justin Warner · Apr 03, 2011 at 03:53 AM
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
Also, to make it per a second... I'd get the time, add on 100 ms, then check it only when the new time (with 100 ms +), is less than the time time... If that makes sense... look at time.time
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.
Well, to be of all honesty, you're going to have to learn how to write code... It's a requirement in my opinion to really do anything with Unity... If you spend about 6 hours going through a script, and understanding how it works, and go through the API (Linked to it), you can easily figure it out... Every thing in the API has examples in both Javascript and C#, now you just have to take the time to go through it... If you need guidance, post what you can come up with, and I'll be glad to edit it and make some changes for you, same with others... Not going to "just write a script" for you =).
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 deter$$anonymous$$es 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..
Your answer
Follow this Question
Related Questions
Attack Script problem please help 1 Answer
Disable a target after trigger exit? 1 Answer
Ai that applies damage in collision? 1 Answer
How to create/fix fire damage script???? 1 Answer
Zombie attack script help 1 Answer