Hey Community,
Quick Query and annoying problem. I have two Objects; one object is my player and my other object is my enemy. I want to send a RPC call to the player from the enemy using two separate scripts. How would I do this?
Regards
- 34638a
Hey Community,
Quick Query and annoying problem. I have two Objects; one object is my player and my other object is my enemy. I want to send a RPC call to the player from the enemy using two separate scripts. How would I do this?
Regards
Unity likes to send RPCs to your mirror, so I just work with that. Tell yourself (on the other machine) to tell the enemy something. In other words, the part where you say enemy1.heresYourLawnmower()
, break that off into a [RPC] function.
If I’m right, sequence will be: player on machine A makes RPC; player on machine B gets it; playerB calls function on enemyB.
You just have to use the NetworkView of your enemy object to send the rpc, that’s all.
// in your player script
//C#
GameObject enemy;
void TellEnemy()
{
Enemy.networkView.RPC("EnemyAction",RPCMode.All);
}
//in a script on the enemy
[RPC]
void EnemyAction()
{
// ...
}