Street Racing 2D (Share_Score)

 using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.IO;


public class Share_Score : MonoBehaviour

{

int highScore = 0;

string appName;

string message;

string link;


    // Update is called once per frame

    void Update()

    {

        

    }


public void ShareScore()

    {

appName = "Street Racing 2D";

link = <App Link>;

message = "I scored a new HighScore of " + highScore.ToString() + " in " + appName + ". \n\n Try to beat me highscore in this game.\n\n Here is the link: " + link;


StartCoroutine(TakeScreenshotAndShare());

}


private IEnumerator TakeScreenshotAndShare()

{

yield return new WaitForEndOfFrame();


Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);

ss.Apply();


string filePath = Path.Combine(Application.temporaryCachePath, "shared img.png");

File.WriteAllBytes(filePath, ss.EncodeToPNG());


// To avoid memory leaks

Destroy(ss);


new NativeShare().AddFile(filePath).SetSubject(appName).SetText(message).Share();

}

}


0 Comments: