I don’t really understand javascript, but hte “no receiver” error message appears when the object receiving the broadcast does not have any active component (or the object is disabled) to receive the message. Also… the code looks strange. I mean, where are you specifying who to broadcast the message? It looks more like you are broadcasting the message to the sending object itself.
var fireRate : float = 0.5;
private var nextFire : float = 0.0;
var Enemy : GameObject[]; // Making the variable to be an array
function Update ()
{
nextFire = Time.time + fireRate; // Decides Rate of fire
if (Input.GetButton ("Fire1") Time.time > nextFire) {
SendNewMessage(); //Calling the function
}
}
function SendNewMessage(){
// Define Enemy with all Gameobjects with tag "Enemy"
Enemy = GameObject.FindGameObjectsWithTag("Enemy");
//List up all the enemy it could find, and then send it.
for(var i = 0; i<Enemy.length; i++){
Enemy[i].SendMessage("ApplyDamage");
}
}
And the enemy have this script:
var Player : GameObject;
Player = GameObject.Find("Player");
var distance : float;
function Update ()
{
distance = Vector3.Distance(transform.position, Player.transform.position);
}
function ApplyDamage (){
if(distance < 20){
Debug.Log("ramt");
Destroy (gameObject);
}
}