Increasing a Players experience if they've hit.

When my player casts a spell he calls an RPC which instantiates an object.
if (Input.GetButton ("Fire1")) {
				if (cooldown < 1) {
					return;
				}
				Vector3 pos = Camera.main.transform.position + Camera.main.transform.forward - Camera.main.transform.up;
				Quaternion rot = Camera.main.transform.rotation;
				Vector3 move = pos + Camera.main.transform.forward;

				pv.RPC ("CastSpell", PhotonTargets.All, selectedSpell, pos, rot, move);
				cooldown = fireRate;
			}

Then method that grabs the RPC is here:
[RPC]
	void CastSpell(string spellName, Vector3 pos, Quaternion rot, Vector3 move){

		Debug.Log ("Casting Spell " + spellName);

		var spell = (GameObject) Instantiate(Resources.Load(spellName), pos, rot);
		var prefabSettings = spell.GetComponent<PrefabSettings>();
		var go = new GameObject ();
		go.transform.position = move;
		prefabSettings.Target = go;
		Destroy (go, 7f);

		
	}

Then the spell behaves according the script attached to that prefab, does damage if it hits, plays audio, etc etc. All this works perfectly. The problem is that I have no way of knowing what player shot the spell so that if it hits award that player experience. I'd like to send the playerInfo (whatever that is) to the script attached to the prefab so I can do the xp reward on collision. Do you have any advice on how to make this work?

Comments

  • I think I fixed this. I just renamed the player prefab on spawn to the PhotonNetwork.player.name and then to find the player just did a GameObject.Find(playerName) seems to work.
  • Good that your solution works.
    You can also pass PhotonNetwork.player.ID as parameter to CastSpell RPC call. That will be id of player shot the spell.