I made like this, first when my character(let’s say player) press key [fire], player’s script calculate if it is critical(50%).
… first see the code,
var bullet : GameObject;
function update(){
if (Input.GetKey(KeyCode.Alpha2))
Fire();
crihit(50); // critical probability
}
function crihit(crichance : float)
{
if (Random.value <= crichance * 0.01)
{
bullet.SendMessage("critical" );
}
}
function fire()
{
Instantiate(bullet, barrel.position, barrel.rotation);
}
And then, my bullet’s script is,
var crieffect : Transform;
private var crihit : boolean=false;
function critical()
{
crihit = true;
}
function OnCollisionEnter(hit : Collision) {
if (crihit){
hit.gameObject.SendMessage("ApplyDamage", damage *2, SendMessageOptions.DontRequireReceiver);
Instantiate(crieffect, transform.position, transform.rotation); Destroy(this.gameObject);
}
else
{
hit.gameObject.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
Instantiate(deathParticles, transform.position, transform.rotation); Destroy(this.gameObject);
}
}
But, when I play game and shoot, error says,
(SendMessage critical has no receiver!)
I don’t know why?
How to fix this?
Or another way to achive my goal?
I thought switching missile itself to a critical missile but I want missile itself changing.