8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityでのTweet対応ボタンの作成(個人的メモ的なアレコレ)

Posted at

ゲームジャムとかで毎回使う(?)ツイートボタン。
ささっと導入できる様にメモとしておいておきます。
また、マルチタップに対応すると組み合わせるとマルチタップないし、Android等でのタップにも対応できるようになります。
また、簡易化とか出来るようでしたら、ご指導、ご鞭撻を宜しくお願いします。

using UnityEngine;
using System.Collections;

public class tweet_button : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	/// <summary>
	/// Fixeds the update.
	/// </summary>
	void FixedUpdate()
	{
        //上で説明のときにあったリンクを参考にしてね
		CheckTap();
        
        //左クリックされたとき
		if(Input.GetMouseButtonDown(0))
		{
            // score -> 変数
            if (this.gameObject.guiTexture.HitTest(Input.mousePosition))
			{
                string message = "" + score + "ここに勝手に入れておいてほしい文字 #ハッシュタグ";
                Application.OpenURL("http://twitter.com/intent/tweet?text=" + WWW.EscapeURL(message));
			}
		}
	}

    // こっちでもいいけど、こっちは1フレームのみのクリックは反応しないかも。
    void OnMouseDown()
    {
        string message = "" + score + "ここに勝手に入れておいてほしい文字 #ハッシュタグ";
        Application.OpenURL("http://twitter.com/intent/tweet?text=" + WWW.EscapeURL(message));
    }

}

こんな感じになります←クリックするとツイート画面に行きます

scoreは基本的に保持していたスコアなり何なりの変数をおいておけば勝手にその数値が入ります。
基本的な部分ですね。 別シーンから数値を保持したいだのに関してはUnityで共通データ(ScriptableObjectとPlayerPrefs)
ここら辺とか参考にしてください。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?