Hi all,
I need help to parenting an object instantiaded via Networking
I've an object called SpellGenerator attached to players.
When i press a button i would like to cast a spell that play a particle (a magic shield) and update the player's stats.
I have created an object Named FireShield with the script attached for play the particle.
The problem is that when i hit the button the object is instantiated as child of SpellGenerator correctly only in the device i'm instatiating.
In others the spell are instatiated but in position 0 0 0 in world space.
How can i parenting the spell to attach to the correct player?
here the code:
public void CastSpell(SpellType spellType)
{
switch (spellType)
{
case SpellType.Shield:
Debug.Log("Calling RPC_CastCircleSpell");
//networkView.RPC("RPC_Cast", RPCMode.All);
GameObject test = (GameObject)Network.Instantiate(circleSpell, transform.position, Quaternion.identity, 0);
//this works locally
test.transform.parent = transform;
break;
case SpellType.ShortShot:
break;
default:
break;
}
}
public class FireShield : MonoBehaviour, IBuff
void OnNetworkInstantiate(NetworkMessageInfo info)
{
//HOW CAN I ATTACH FIRESHIELD TO THE CORRECT SpellGenerator and apply buff to the correct player?
BuffDurationTimer = BaseBuffDuration;
Transform particle = gameObject.transform.FindChild("Dark_Main");
particle.particleSystem.Play();
}
there is a better way to do what i am trying to do?
thank you for help
↧