# Problem Calling Function from Other Script

**URL:** https://discussions.unity.com/t/problem-calling-function-from-other-script/170802
**Category:** Questions & Answers
**Created:** [August 11, 2016, 4:53pm UTC](https://discussions.unity.com/t/problem-calling-function-from-other-script/170802 "2016-08-11T16:53:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![KaiserDE](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@KaiserDE](https://discussions.unity.com/u/KaiserDE)
#### Post date: [August 11, 2016, 4:53pm UTC](https://discussions.unity.com/t/problem-calling-function-from-other-script/170802/1 "2016-08-11T16:53:42Z")

</div>

So basically I have two scripts, the enemy health script that I attach to the enemy that goes as follows.

```
#pragma strict
 var Health = 100;
 var animDie : AnimationClip; // Drag your animation from the project view in here (to inspector)
 
 function ApplyDammage (TheDammage : int)
 {
     Health -= TheDammage;
     if(Health <= 0)
     {
        Dead();
     }
 }
 
 function Dead()
 {
     GetComponent.<Animation>().Play(animDie.name);
     Destroy(this.gameObject, animDie.length);
 }

```

I also have the script that I attach to my Bullet, that goes as follows…  
#pragma strict

```
function OnCollisionEnter (col : Collision)
{
	if(col.gameObject.name == "char4_snipersnest_char4")
	{
		gameObject.SendMessage("ApplyDammage",100);
	}
}

```

However, when they collide the console says the following: “SendMessage ApplyDammage has no receiver!” I’ve seen some other threads on the SendMessage has no Receiver problem but I can’t quite follow them in my case. Any help here would be massively appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![Hethu](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hethu](https://discussions.unity.com/u/Hethu)
#### Post date: [August 12, 2016, 7:39am UTC](https://discussions.unity.com/t/problem-calling-function-from-other-script/170802/2 "2016-08-12T07:39:06Z")

</div>

I do not know if it works in JS but this is my C# Script for the Bullet/Laser:

I hope it will help somehow.

```
public class LaserDamage : MonoBehaviour {

	public float damage = 1;

	void OnTriggerEnter2D (Collider2D other)
	{
		if (!other.CompareTag ("Player")) 
		{
			other.SendMessage("ApplyDamage",damage,SendMessageOptions.DontRequireReceiver);
			Destroy(gameObject);
		}
	}
}

```

---

<div class="post-metadata">

### Author: ![Subcursion](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@Subcursion](https://discussions.unity.com/u/Subcursion)
#### Post date: [August 12, 2016, 2:18pm UTC](https://discussions.unity.com/t/problem-calling-function-from-other-script/170802/3 "2016-08-12T14:18:42Z")

</div>

Actually as I look at your Bullet script @KaiserDE, you are asking the Bullet script for the method ApplyDamage when it’s actually you’re enemy that has that method.

```
function OnCollisionEnter (col : Collision)
 {
     if(col.gameObject.name == "char4_snipersnest_char4")
     {
         //asks the bullet script for the method ApplyDammage (no method exists)
         gameObject.SendMessage("ApplyDammage",100); 
         //the below should work since the method you want is on the enemy object
         col.gameObject.SendMessage("ApplyDammage",100);
     }
 }

```
