Hiding Scripts for Multiplayer

Hi guys,

I am making a local split-screen multiplayer game which may progress to online at some point. In short, I have a problem similar to that of the multiple camera problem when it comes to multiplayer, but with scripts. I have two players with identical sets of scripts, but certain scripts interfere with the running of the corresponding one on the other player.

An example of this is a script I have that can spawn objects nearby the player and works perfectly well when I run the game with one player, but with two the object spawns near the wrong player as this too shares the same script with the same GUI controls etc. I n this instance I have two overlapping cameras and GUIs, yet the scripts require a camera to be attached to the player for targeting to be unique to the player. I could disable the script, but quite clearly this wouldn’t allow the second player to spawn the object anymore.

To note, I was careful to code my scripts with multiplayer in mind; everything I have written is specific to the player prefab itself and does not interact with the wider scene unless explicitly required to.

Is there a way of hiding the scripts on one player so that the script runs exclusively for one player/camera and is not seen by the other (similar to the way a private variable for a class is present and usable by the script it is defined in but not visible by other scripts)? For example, a player generally only needs to have access to the other player’s health, etc. to do damage and not their movement scripts.

Cheers,

Popuppirate

I beleive you are looking for networkView.isMine (if you’re using network view components)