I have been following tutorial at 1 and got stuck trying to make the capsule game object receive message sent from another object.
I am using built in controller object and added a script to its camera:
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
print ("Did Hit");
if(Distance < MaxDistance)
{
print ("message sent");
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
I created a capsule object and added this script:
var Health = 100;
function ApplyDamage (damage : int)
{
Health -= damage;
print ("message received");
}
In game view, when I move really close to the capsule and click on it, nothing happens.
I see message saying the message has been sent but i don’t see “message received” in console. The capsule has collider component.
When i add the same script to another cube object, it does the right thing.
Is this a bug?