code ソーシャル

Unityアプリcodetips(49)

スポンサーリンク

//tips

//Stage番号のUI表示

UI表示に現在進行中のstage番号も記載する。

PlayerPrefsを使ってstage番号の呼び出しを行う。

Text内で改行して文言記載を行う場合は/nを使用する。/nは文字と同じ認識なので””で囲わなければならない。

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

using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class UItext : MonoBehaviour
{
[SerializeField] UnityEngine.UI.Text textbox;

public int playstage;

void Start()
{
//PlayerPrefs.DeleteAll();

int clearStageNo = PlayerPrefs.GetInt("CLEAR", 0); //どのステージまでクリアしているのかをロード(セーブされていなければ「0」)

Debug.Log(clearStageNo);

int playstage = PlayerPrefs.GetInt("playstage", 1);

if (clearStageNo ==0)
{
textbox.text = "称号:"+"お使い"+"\n"+"STAGE"+ playstage;

}

if (clearStageNo == 1)
{
textbox.text = "称号:" + "散歩" + "\n" + "STAGE: " + playstage;
}

if (clearStageNo == 2)
{
textbox.text = "称号:" + "スキップ" + "\n" + "STAGE: " + playstage;
}

if (clearStageNo == 3)
{
textbox.text = "称号:" + "ランニング" + "\n" + "STAGE: " + playstage;
}

if (clearStageNo == 4)
{
textbox.text = "称号:" + "ダッシュ" + "\n" + "STAGE: " + playstage;
}

if (clearStageNo == 5)
{
textbox.text = "称号:" + "転身" + "\n" + "STAGE: " + playstage;
}

if (clearStageNo == 6)
{
textbox.text = "称号:" + "変わり身" + "\n" + "STAGE: " + playstage;
}

}
}

//SNSの組み込み設定

ゴールシーンにSNSの連携を組み込む。
下記参照。

【Unityスクール】SNSにスクショをシェアする機能の実装方法

SocialConnector.unitypackageをダブルクリックでassets下にインポートできる。

インポートしたSocialConnectorの中にスクリプトも記載されているのでボタンを押したらシェアできるように設定する。

下記を参考に作成しているがエラーが発生しているので確認中。

エラー内容は、インストールしたSocialConnectorが読み込めないというもの。twitterボタンへのメソッドのアタッチも項目が表示されずできない状態。

また、write accessの設定が、Other Settingsの項目に見つからない。

Assets/script/SNS/SNS.cs(34,9): error CS0234: The type or namespace name 'Share' does not exist in the namespace 'SocialConnector' (are you missing an assembly reference?

using UnityEngine;
using System.IO;
using System.Collections;
using SocialConnector;
using UnityEngine.UI;

public class SNS : MonoBehaviour
{
public void Share()
{
StartCoroutine(_Share());
}

public IEnumerator _Share()
{
string imgPath = Application.persistentDataPath + "/image.png";

// 前回のデータを削除
File.Delete(imgPath);

//スクリーンショットを撮影
ScreenCapture.CaptureScreenshot("image.png");

// 撮影画像の保存が完了するまで待機
while (true)
{
if (File.Exists(imgPath)) break;
yield return null;
}

// 投稿する
string tweetText = "";
string tweetURL = "";
SocialConnector.Share(tweetText, tweetURL, imgPath);
}
}

//UnityAdsの実装

現在UnityAdsをunityに表示させるテスト中であるが、Advertisement.IsReady()の読み込みがうまくいかず、検証中。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class testads : MonoBehaviour
{
void Update()
{
// if (Input.GetKeyDown(KeyCode.Space))

FunctionTest();
Debug.Log("a");
}

void FunctionTest()
{
Debug.Log("b");

if (Advertisement.IsReady())
{
Advertisement.Show();
Debug.Log("c");
}
}
}

 

 

人気の記事

1

皆さん、ついに、エアラインでも、サブスクリプションが始まったのはご存じですか? まだ実験段階ですが、ANAが、定額全国住み放題サービスを提供する「ADDress」と組んで、国内線を4回まで定額利用可能 ...

2

無料でネットショップを開けるアプリとして多くの人に驚きを与えたBASE株式会社が、2019年10月25日東証マザーズに上場しました。2020年2月時点で90万店を超えるショップを抱えるまでに成長してい ...

3

2011年にサービスを開始してから圧倒的な成長率を誇るインテリア通販サイト 【FLYMEe/フライミー】を皆さんご存じでしょうか。 「自分のイメージするインテリア、本当に欲しいインテリアがどこにあるの ...

4

ついに、noteの月間アクティブユーザー数が4400万人(2020年3月時点)に到達しました。 そもそも、「note」とは、クリエイターが、文章やマンガ、写真、音声を投稿することができ、ユーザーはその ...

5

ボードゲームカフェが1日2回転で儲かるという記事をみつけたので興味を持ち、調べてみました。 まずは、需要がどれくらいあるのか、市場のようすからみていきましょう。 世界最大のボードゲーム市場はドイツで、 ...

-code, ソーシャル
-,

Copyright© BUSINESS HUNTER , 2023 All Rights Reserved Powered by AFFINGER5.