//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の連携を組み込む。
下記参照。
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");
}
}
}