Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Simple Example to begin with Photon PUN multiplayer game development

Posted on November 29, 2022May 29, 2024 by Habibie

This simple script is to connect the game to Photon server and instantiate a player prefab on your Resources folder. Make sure your player prefab has PhotonView component in it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class SimpleLauncher : MonoBehaviourPunCallbacks
{
	
	public PhotonView playerPrefab;
	
    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
    }

	public override void OnConnectedToMaster(){
		Debug.Log("Connected to Master");
		PhotonNetwork.JoinRandomOrCreateRoom();
	}
	
	public override void OnJoinedRoom(){
		Debug.Log("Joined a room.");
		PhotonNetwork.Instantiate(playerPrefab.name, Vector3.zero, Quaternion.identity);
	}
	
}

Check out this video on how to use it:

Ready to develop more? Watch out the next steps of what we can do with Photon PUN 2 in this video tutorial playlist: https://www.youtube.com/playlist?list=PLtZUQWWVMRK3IKODhhxo-WBzTeIgWTszW

Post Views: 1,317
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme