Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

unity3d - Efficient way to check where the bullet came from player [Unity Multiplayer Mirror]

I'm new to mirror so bare with me. What I'm trying to do is when a player gets hit by the bullet of another player it can check whose bullet came from my option is:

1.) add player tag to bullet 

or there is a better way using mirror

question from:https://stackoverflow.com/questions/65643620/efficient-way-to-check-where-the-bullet-came-from-player-unity-multiplayer-mirr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Attach Network Identity to root of bullet to ensure it spawns on other clients.
  2. Create a NetworkBehaviuor script to manage any logic or data associated with the bullet.
  3. Add a single int firingPlayerId; field with the [SyncVar] attribute to the script.
  4. Update this variable whenever a player uses this object as a bullet to shoot (assuming you have some kind of caching going on, you'd need to change this).

Since NetworkIdentity makes sure variables are only synced when they are modified/dirtied, this won't cost you anything.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...