- Home /
I'm trying to add a 3rd and possible more weapons to this script what am I missing??
I'm trying to add a 3rd and possibly more weapons to this script but I keep getting a message asying that "BroadcastMessage Fire has no reciver" whatever that means, and yes before you ask I'm new to this whole scripting stuff, model building is more my bag of tricks, but I'm trying to learn something new. Here is my script:
function Start () { // Select the first weapon SelectWeapon(0); }
function Update () { // Did the user press fire? if (Input.GetButton ("Fire1")) BroadcastMessage("Fire");
if (Input.GetKeyDown("1")) {
SelectWeapon(0);
}
else if (Input.GetKeyDown("2")) {
SelectWeapon(1);
}
else if (Input.GetKeyDown("3")) {
SelectWeapon(2);
}
}
function SelectWeapon (index : int) { for (var i=0;i<transform.childCount;i++) { // Activate the selected weapon if (i == index) transform.GetChild(i).gameObject.SetActiveRecursively(true); // Deactivate all other weapons else transform.GetChild(i).gameObject.SetActiveRecursively(false); } }
Any help on this would be greatly apreciated :)
Answer by Jason_DB · Feb 14, 2011 at 01:10 AM
Broadcastmessage("Fire") looks for a function called 'fire' in an object or any of it's children, and then calls it. 'BroadcastMessage Fire has no receiver' means that the message you're broadcasting can't find a function called 'fire', so you're probably missing a script on the gun. I would check again to make sure your 3rd gun has all the proper scripts on it, or even start by duplicating the second and then tweaking it.
Yup, that was it, now if I can just figure out why my grenade launcher is not causing any damage when basically it has the same script that the rocket launcher has :doh:
Figured it out, my Explosion from the detonator add on pack was missing the java script that enabled it to give damage... lol it's always the simple things eh? ;)
Now I can't seem to get my 3rd weapon which is the Grenade launcher to work with their part of the GUI tutorial, I've tried tweaking those varialble to no end and it keeps giving me an error in the "FPSPlayer.js" that reads: Assets/WeaponScripts/FPSPlayer.js(15,31): BCE0018: The name 'GrenadeLauncher' does not denote a valid type ('not found').
Now in my First person Controller game object's weapons my grenade launcher is named thusly:
Launcher -GrenageLauncher (all the parented ojects under that as I'm using my own custom model)
I can't figure out what i'm missing??
Answer by BadProxy Latzo · Feb 16, 2012 at 03:41 PM
The file containing the code "BroadcastMessage Fire" must be equal to or a child of the file that contains the method Fire(), otherwise the BroadcastMessage won't find the method.