Example #1
0
    void Update()
    {
        if (PV.IsMine)
        {
            if (teamToken.teamCaptain != null || !waitForTeamToken)
            {
                foreach (string objectName in objectNames)
                {
                    GameObject go = PhotonNetwork.Instantiate(
                        Path.Combine("PhotonPrefabs", folderName, objectName),
                        transform.position,
                        transform.rotation
                        );
                    //Color
                    ColorInitializer colorInit = go.FindComponent <ColorInitializer>();
                    if (colorInit)
                    {
                        colorInit.setColor(PlayerColor);
                    }
                    //Delegate
                    if (onObjectSpawned != null)
                    {
                        onObjectSpawned(go);
                    }

                    TeamToken.seeRecruiter(go, teamToken.owner, true);
                }
                PhotonNetwork.Destroy(this.gameObject);
            }
        }
    }
 public GameObject spawnObject(ObjectSpawnInfo osi, Vector2 pos, Vector2 dir, float addSpawnBuffer = 0)
 {
     if (PV.IsMine)
     {
         //Make sure dir is a unit vector
         if (!Mathf.Approximately(dir.sqrMagnitude, 1))
         {
             throw new System.ArgumentException(
                       $"dir needs to be a unit vector! dir: {dir}, " +
                       $"sqrMagnitude: {dir.sqrMagnitude}"
                       );
         }
         //Initialize arguments
         string  pathName = Path.Combine("PhotonPrefabs", folderName, osi.objectName);
         Vector2 position = pos + (dir * (osi.spawnBuffer + addSpawnBuffer));
         position += osi.spawnOffset;
         Quaternion rotation = (osi.rotateShot)
             ? Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.up, dir))
             : Quaternion.Euler(0, 0, 0);
         //Instantiate
         GameObject go = (SpawnMaster)
                         //Spawn as scene object (doesn't disappear when player disconnects)
             ? PhotonNetwork.InstantiateRoomObject(pathName, position, rotation)
                         //Spawn as player object (disappears when player disconnects)
             : PhotonNetwork.Instantiate(pathName, position, rotation)
         ;
         //Team Token
         if (osi.inheritTeamToken)
         {
             TeamToken.seeRecruiter(go, teamToken.owner, true);
         }
         //Color
         if (osi.inheritColor)
         {
             ColorInitializer colorInit = go.FindComponent <ColorInitializer>();
             if (colorInit)
             {
                 colorInit.setColor(PlayerColor);
             }
         }
         //Delegate
         onObjectSpawned?.Invoke(go, position, dir);
         //Return
         return(go);
     }
     return(null);
 }