Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

SendMessage has no reciever

$
0
0
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); } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>