How to make Melee damage?

I have been searching alot for this but I found nothing.
I need to make a sword damage the happends when the sword touchs a specific (object/tag/anything if you cant).
and please write a script explaining every single letter, symbol etc…
Oh and iam using a slash animation so I want the collider to move with it.

http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

What does this do ?
I cant find anything helpful in both of these links.

Then why are you here? Unless you’re wanting to learn C#, then look for a C# guide.

You’re wanting for us to give you run down on every single letter, symbol, etc - the JS guide works with C# in that regard fairly as well.

The second link is documentation. Look up different methods such as raycasting, vector3 distance, OnCollisionEnter, normals, etc to calculate how the sword is hitting another object.

This ain’t gonna happen.

  1. I suggest to add a rigidbody to the sword. Also add rigidbodies to destroyable objects.
  2. Set the rigidbody of the sword to kinematic=true. This will remove physics influence on the sword but detect collisions.
  3. You can tag all destroyable objects a certain tag and then do some action on collision.

I remember when I was young, one day my Dad brought home a music casio keyboard, he laid it down in front of me and said “learn”. I tried to brain it out for a week, trying all sorts of combinations. Needless to say, I never learned to play.

@CrazySi - The difference here is, code (in it’s simplest form, especially JS) is very easy to learn - it’s almost self explanatory in many situations even to a non-coder IMO. All it takes is a little focus.

@OKM - you need to learn the very basics first, then jump into the more advanced stuff. Without showing some initiation on your part to read through syntax, why are we to help you learn specific syntax of a particular code snippet that may do what you want?

Ok atleast give me a script for it please.
and i never understood what does ( collision : Collision ) in the OnCollisionEnter function.
and i have completed the newbie guid above.

Basically, OnCollisionEnter which is a function:

Is called when any object enters collision - say for example your sword which has a box or mesh collider hits any other sort of collider, that collision “starts” - it enters the collision mode. So, when this happens it executes the code in the function.

So, say in terms of pseudo theory:

  1. You want an object, a sword with a collider set up
  2. To check what the sword hits “OnCollisionEnter” with say, a tag (which is faster than looking up "hit object name “enemy007” you would check the tag “Enemy”:
    Unity - Manual: Tags
    Unity - Manual: Tags and Layers
    Unity - Scripting API: GameObject.tag
  3. Then apply damage to the enemy’s script variable for example, by getting the component of the Enemy:
    Unity - Scripting API: Component.GetComponent

Break down every aspect on how something may be executed, and then look at how you’ll code each part. With that logic, you can google/go through the unity docs and easily find references to what you need to help you make a basic system.

Thanks I really understood now and I will try it now .

Is this script Right ?
var jump = 5;
var speed = 5;
var Idle = true;
var rotSpeed = 5;

function Update () {
if(Input.GetButton(“Fire1”)){
animation.Play(“Attack_1”);
Idle = false;
}
var y = Input.GetAxis(“Horizontal”) * Time.deltaTime * rotSpeed;
var z = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
transform.Translate(0, 0, z);
transform.Rotate(0, y, 0);
if(Input.GetButton(“Vertical”)){
animation.CrossFade(“Run”);
Idle = false;
}
if(!animation.IsPlaying(“Run”)){
animation.PlayQueued(“Idle”,QueueMode.CompleteOthers);
}
if(Input.GetButtonDown(“Jump”)){
transform.Translate(0, jump, 0);
}
}
function OnCollisionEnter ( tag : Enemy ){
Destroy(gameObject);
}