Hi guys, I’ve spent the last four days on this and it has consumed me every waking second.
I’m working in FPS KIT 2. All I’m looking to do is to give a player a gun once he reaches a certain amount of kills. I’m able to pull the kills from the server, play a sound, etc. But trying to actually give him the gun is quite the challenge!
I’ve tried sendmessage, broadcastmessage, getcomponent, getcomponentsinchildren. Here’s the gist of it;
UpgradeLine.CS
public AudioClip UpgradeSound;
bool upgraded;
int prevKills = 0;
GameObject player = GameObject.FindGameObjectWithTag("Player");//Find local player
string[] upgradeTemplate = new string[10];
public GameObject upgrade3;
void Update () {
upgraded = (bool)PhotonNetwork.player.customProperties["Upgraded"];//Get weather we have been upgraded from the server
upgradeLine((int)PhotonNetwork.player.customProperties["Kills"]);//I have no idea what i'm doing so I"m pulling kills from the server and hoping
}
void upgradeLine(int kills){
if(upgraded == false){ //Don't do anything unless we haven't been upgraded yet
if(kills == 3 && kills != prevKills){ //Kill three
BroadcastMessage("addUpgradedGun", upgrade3);
upgraded = true;//Okay, we've been upgraded
Hashtable setPlayerUpgraded = new Hashtable() {{"Upgraded", upgraded}};//Tell server we've been upgraded
PhotonNetwork.player.SetCustomProperties(setPlayerUpgraded);
prevKills = kills;
audio.clip = UpgradeSound;//play sound
audio.Play();
}
} else {
upgraded = false;
}
And then here’s the receiver, which is located on the same gameobject, not a child:
WeaponPickUp.js
public function AddUpgradedGun(gunAdd : WeaponScript){
weapManager.allWeapons.Add(gunAdd);
weapManager.SwitchWeapons(weapManager.SelectedWeapon.gameObject, weapManager.allWeapons[weapManager.allWeapons.Count-1].gameObject);
weapManager.index = weapManager.allWeapons.Count-1;
//Register Action
actionsList.Add(("Picked | " + gunAdd.weaponName).ToString());
}
I’ve tried placing the JS files in a folder called Standard Assets, I’ve also tried it the other way around with the CS files. Here’s the error with this exact code:
BroadcastMessage addUpgradedGun has no receiver!
UnityEngine.Component:BroadcastMessage(String, Object)
UpgradeLine:upgradeLine(Int32) (at Assets/FPS Kit Version 2.0/_CustomAssets/Scripts/Network C#/UpgradeLine.cs:49)
UpgradeLine:Update() (at Assets/FPS Kit Version 2.0/_CustomAssets/Scripts/Network C#/UpgradeLine.cs:39)
Using the same thing with getComponent and declaring private WeaponPickUp weapPickUp, It won’t even let me compile, stating:
error CS0246: The type or namespace name `WeaponPickUp' could not be found. Are you missing a using directive or an assembly reference?