Need GameObject to be active only in master client scene.

Options
Hi,
I got a tower object with "TowerScript" attached that fires projectile, i need this "TowerScript" to be active only on the master clients side.
So the other players dont fires projectiles.

I tried to disactivate the script when:
- photonView.ismine == false
- PhotonNetwork.isMasterClient
- thisPhotonView.isSceneView
- thisPhotonView.owner.isLocal

with combinations

Could not find the right way...

Any help please ?

Paradoks

Comments

  • Paradoks
    Options
    I got this tower, and i want only one players computer to be able to manage it, the other will receive RPC's
    Anybody ?
  • Paradoks
    Options
    how do you get acces to "controlled locally" bool ? is that the isMine ?
    Why is it enabling it after a few second after the connection ?
  • Paradoks
    Options
    Ok did a little mistake, now the start code is into "void OnJoinedRoom()"

    but when it does the code my tower is at x0,y0 on the map.. any hint why ?
  • vadim
    Options
    Hi,

    photonView.isMine returns true for object owner. You can disable script for non-owners on Awake:
    public void Awake()
    {
        if (!photonView.isMine)
            this.enabled = false;  
    }
    
    Or, if script should be enabled, wrap code in if (photonView.isMine) { ... } blocks to run it on owner only.
    but when it does the code my tower is at x0,y0 on the map..
    What you mean? It's placed at wrong position? Do you synchronize tower positions?
  • Paradoks
    Options
    i am using this :
    			if (thisEntityManager.thisEntityType == EntityManager.EntityType.isBuilding){
    				
    				if (PhotonNetwork.isMasterClient) {
    				
    					this.enabled = false;
    					thisEntityManager.enabled = true;
    					if ( isSpawningEntity == true) { thisSpawner.enabled = true;}
    				
    				}else {
    				
    					this.enabled = false;
    					if ( isSpawningEntity == false) { thisSpawner.enabled = false;}
    					thisEntityManager.enabled = false;
    				}
    				
    				transform.position = thisPermanentPosition;
    			}
    

    in the OnJoinedRoom() function, but when it does the code it puts the tower at X = 0, Y = 0 coordinates so i need to use this
    "transform.position = thisPermanentPosition;"
    like if it was instatiating it without starting coords

    any hint ?
  • vadim
    Options
    How do you instantiate the tower? Is it put in scene in editor or spawned dynamically with PhotonNetwork.Instantiate or PhotonNetwork.InstantiateSceneObject?
    In both cases position should be proper w/o any additional effort.
  • Paradoks
    Options
    I dont instantiate the tower, it is scene owned.
    strange ?
  • Tobias
    Options
    Towers? Sounds like a tower defense game?
    Are you placing towers or are they static?

    PUN will not move static scene objects, unless your code does it somehow. So please double check where you access the transform, etc.
    OnPhotonSerializeView() is a method that's often used to synchronize positions of GOs. Maybe you copied one of those scripts into your tower?

    You set this.enabled to false in both cases. Is that the plan?