Skip to main content

How to setup Photon Networking in unity so we can use it from UnityScript ( Unity js )

When i first try to convert this simple c# code to unity js or unityscript, I got this error :

The name 'PhotonStream' does not denote a valid type ('not found')
The name 'PhotonMessageInfo' does not denote a valid type ('not found')

here is the c# version that i found on Photon Networking Example.
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation); 
        }
        else
        {
            //Network player, receive data
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
        }
    }

And here is the JS version
function OnPhotonSerializeView(stream : PhotonStream, info : PhotonMessageInfo)
{
    if (stream.isWriting)
    {
        //We own this player: send the others our data
        stream.SendNext(transform.position);
        stream.SendNext(transform.rotation); 
    }
    else
    {
        //Network player, receive data
        correctPlayerPos = stream.ReceiveNext();
        correctPlayerRot = stream.ReceiveNext();
    }
}


I found a simple Solution on the Internet  So i thought i should share this with you guys.
Drag the Plugins folder from Photon Unity Networking folder to Asset folder, you can find Asset  folder on top of any untiy project. Now Drag the Utility folder from Photon Unity Networking to Plugins folder, that's it.
Now in my case these lines of code was working perfectly...
function OnPhotonSerializeView(stream : PhotonStream, info : PhotonMessageInfo)
{
    if (stream.isWriting)
    {
        //We own this player: send the others our data
        stream.SendNext(transform.position);
        stream.SendNext(transform.rotation); 
    }
    else
    {
        //Network player, receive data
        correctPlayerPos = stream.ReceiveNext();
        correctPlayerRot = stream.ReceiveNext();
    }
}



Comments

Popular posts from this blog

How to write data to CSV file in UNITY

Hi Guys, if any one is facing problem to save data in csv file can use this solution. If you have any questions, you can ask me through comments.

Things to remember :
Never ever add any commas to your data otherwise, cells will get messed up completely. 


Results :


Here is the code

usingUnityEngine;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.IO;
usingSystem;

publicclassCsvReadWrite : MonoBehaviour {

privateList<string[]> rowData = newList<string[]>();


//Usethisforinitialization
voidStart () {
Save();
    }

voidSave(){

//CreatingFirstrowoftitlesmanually..
string[] rowDataTemp = newstring[3];
rowDataTemp[0] = "Name";
rowDataTemp[1] = "ID";
rowDataTemp[2] = "Income";
rowData.Add(rowDataTemp);

//Youcanaddupthevalues

Simple Up, Down, Left, Right Swipe controls for touch devices( Iphone and Android) in unity

Note: There are more than 50 comments in this post, So, if your comment is not appearing on the first page than' 'don't get panic', there is aLoad Morebutton at the bottom of the page.



Here is a UnityScript (javascript version)

#pragma strict
var player : Transform;  // Drag your player here
privatevar fp : Vector2;  // first finger position
privatevar lp : Vector2;  // last finger position

function Update()
{
for (var touch : Touchin Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
fp = touch.position;
lp = touch.position;
}
if (touch.phase == TouchPhase.Moved )
{
lp = touch.position;
}
if(touch.phase == TouchPhase.Ended)
{

if((fp.x - lp.x) > 80) // left swipe
{

player.Rotate(0,-90,0);

}
else if((fp.x - lp.x) < -80) // right swipe
{
player.Rotate(0,90,0);
}
else if((fp.y - lp.y) < -80 ) // up swipe
{
// add your jumping code here
}
}
}


}


add this script to any empty gameObject or your player than drag your player to player variable in editor now build a .apk or .ipa and check the re…

How to create line graph in unity

Hi guys, previously i have shown how you can create Bar_Graph in unity, after successfully showing bar graph in unity i fell in love with graphs, so when i was asked to show data on a line graph, i got excited and came up with this solution, its almost similar to the bar graph, but this time i have made it more reliable and dynamic.

this is how my setup looks like :




I have an orthographic camera in my scene, which only renders a layer i namded "GUI". and every gameobject in the graph are in "GUI" layer.

why orthographic camera ? its because they easily adjust according to different screen resolutions, i have also used textMesh to show the numbers in graph, which again is the best option if you want to show text in 3d space.


here is a view, how the final graph looks like with data :






in the above image you can see that i am showing data for 99 turns,  but in this small space i cant show data for all the 99 turns, so what i did is i made a dynamic function which give…