SendMessage has no reciever
Hi Everyone, I have a really big problem, here is my script, before the raycast I have it set so that a clone of a prefab Grenade is instantiated, what I want to happen is that when I shoot said Grenade, it will explode, I just want to run the Explode() function on the Grenade's script, but it isn't working, I have tried calling it from a variable, but that didn't work, it just gave me compiler errors, so I tried this way, but that didn't work either, please help me : (
Here is the Shooting Script:
//Raycast//
var Raycast : RaycastHit;
if(Physics.Raycast(BulletSpawn.transform.position, fwd, Raycast, 100))
{
Debug.DrawLine(BulletSpawn.transform.position, Raycast.point);
if(Raycast.rigidbody != null && Raycast.rigidbody.isKinematic == true);
{
Raycast.rigidbody.isKinematic = false;
Raycast.rigidbody.AddForceAtPosition(fwd * force, Raycast.point);
}
if(Raycast.rigidbody.tag == "Grenade")
{
Raycast.rigidbody.gameObject.SendMessage("Explode()");
}
}
}
//Recoil//
transform.localPosition = Vector3.SmoothDamp(transform.localPosition, Vector3.zero, ZposV, .2);
}
Here is my Grenade Script:
#pragma strict
var Triggered : boolean;
var radius : float = 30;
var force : float = 7000;
var upforce : float = 700;
var Timer : float = 3;
var Particles : GameObject;
function IsTriggered()
{
Triggered = true;
}
function Start()
{
if(Triggered == false)
{
yield WaitForSeconds( Timer);
Explode();
}
}
function Update()
{
if(Triggered == true)
{
if(Input.GetMouseButtonDown(1))
Explode();
}
}
function Explode ()
{
var explosionorigin : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionorigin, radius);
for(var hit : Collider in colliders)
{
if(Triggered == true)
this.GetComponent(Rigidbody).isKinematic = true;
if(hit.GetComponent(Rigidbody))
{
var rbody = hit.GetComponent(Rigidbody);
rbody.isKinematic = false;
rbody.AddExplosionForce(force, explosionorigin, radius, upforce);
GameObject.Instantiate(Particles, transform.position, Particles.transform.rotation);
Destroy(gameObject);
}
}
}
Just to add, the Grenade prefab does have the right tag
Your answer
Follow this Question
Related Questions
How to return a function 0 Answers
Not all code paths return a value error on a void function 0 Answers
unity doesnt work 0 Answers
I do a enemy movement function and doesnt work 0 Answers
Player not activating method 0 Answers