Thursday 29 June 2017

Facebook Sharing

hey guys, here is the Facebook sharing script, simple way, make sure you have to import Facebook SDK in your unity project,


using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;


public class Facebookmanager : MonoBehaviour {

//--------- login----------

void Awake()
{
if (!FB.IsInitialized)
{
FB.Init ();
}
else
{
FB.ActivateApp ();
}
}

public void LogIn()
{
FB.LogInWithReadPermissions (callback: OnLogIn);
}

void OnLogIn(ILoginResult result)
{
if (FB.IsLoggedIn)
{
AccessToken token = AccessToken.CurrentAccessToken;
}
else
{
Debug.Log("Canceled Login");
     }
}

//------- login end-----------

//-----sharing start-------

public void Share()
{
FB.ShareLink (

contentTitle: "Mad Drift! Love this game!",
contentURL: new System.Uri ("https://yourlinkwhateveryoushare"),
contentDescription: "Mad Drift! Love this game! Download it rate it",
photoURL: new System.Uri ("https://photourl"),
callback: OnShare);
}

void OnShare (IShareResult result)
{
if (result.Cancelled || !string.IsNullOrEmpty (result.Error))
{
Debug.Log ("ShareLinkError: " + result.Error);
}
else if (!string.IsNullOrEmpty (result.PostId))
{
Debug.Log (result.PostId);
      }
else
{
Debug.Log ("Share success");
  }
}

}

Wednesday 28 June 2017

Login With Unity

Hey guys Here is the Simple Login Script With Api

Login.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Login : MonoBehaviour {

public InputField Username;
public InputField Password;
private string LoginAPI="http://YourApiLink";  //Change link with your LoginAPI.

  public void LoginClick()
{
WWWForm form = new WWWForm ();
         //Change username/password with your tabel parameter;
form.AddField ("username",Username.text);
form.AddField ("password", Password.text);

          WWW w = new WWW (LoginAPI,form);
StartCoroutine (LoginFunc(w));
}

IEnumerator LoginFunc(WWW w)
{
yield return w;
if (w.error == null)
{
Debug.Log (w.text);
}
else
{
Debug.Log ("ERROR: " + w.error + "\n");
}
}

}


.. Be Happy .  :) :)

Registration Form Unity

hello guys, here is the simple nice script for registration form with API

Register.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Register : MonoBehaviour {

public InputField Username;
public InputField Email;
public InputField Password;

  //Change link with your RegistrationAPI.
private string RegisterAPI="http://YourAPILink";

  public void RegisterClick()
{
WWWForm form = new WWWForm ();
        //Change username/email/password with your tabel parameter

form.AddField ("username",Username.text);
form.AddField ("password",Password.text);
form.AddField ("email",Email.text);

       WWW w = new WWW (RegisterAPI,form);
StartCoroutine(RegistrationFunc(w));
}

   //Get Responce, e.g. Registration successfully

IEnumerator RegistrationFunc(WWW w)
{
yield return w;
if (w.error == null)
{
Debug.Log (w.text);
}
else
{
Debug.Log ("ERROR: " + w.error + "\n");
}
}

}