Unity
// 煙のimageを取得 GameObject smoke = (GameObject)Instantiate(smokePrefab); // canvasGameオブジェクトの子供に設定 smoke.transform.SetParent(canvasGame.transform, false); smoke.transform.SetSiblingIndex(2);
float scale = 1.0f; transform.localScale = new Vector3(scale, scale, 1.0f);
public Sprite[] templePicture = new Sprite[3]; public void SetTemplePicture(int level) { GetComponent<Image>().sprite = templePicture[level]; }</image>
// 時間の差分をチェック // DateTime型同士の計算は、TimeSpan型になる TimeSpan timeSpan = DateTime.UtcNow - lastDateTime; // RESPAWN_TIME定数の秒数をTimeSpan型に変換 if(timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME)) { while(timeSpan >= Time…
DateTime lastDateTime = DateTime.UtcNow;
private GameObject gameManager = GameObject.Find("GameManager"); gameManager.GetComponent<GameManager>().GetKey();</gamemanager>
1.EventTriggerコンポーネントを追加する。2.Add new Event Type / PointerEnterを選択する。3.+をクリックし、タップした際に呼び出したいメソッドがあるゲームオブジェクトをセットする。4.No Functionをクリックし、対象のメソッドを選択する。
// Prefabから新しいインスタンスを作成 GameObject orb = (GameObject)Instantiate(orbPrefab); // CanvasGameオブジェクトを親オブジェクトに設定 orb.transform.SetParent(canvasGame.transform, false); // 生成したインスタンスの位置を設定 orb.transf…
Cancas / Order in Layerの数値を大きくする。 そうすると、数値が大きいものほど前面に表示される。
Image / Raycast Targetをオフにする。
1.UI / Imageをクリック。2.Source Imageのアイコンをクリックし、表示したいスプライトを選択。3.Set Native Sizeをクリックすると、もとの画像の大きさで表示される。
iOSアプリをAppStoreへ公開するまでの流れは一通り分かったので、次は色々こだわったゲームを作ろうと思う。けど、まだまだ自分ができることは少ないので、あくまで出来る範囲で。 まずは今作っているゲームの概要から。基本は「落ちゲー」で、ひたすら落下…
// 移動速度 public float speed = 5.0f; // Rigidbodyコンポーネント Rigidbody2D rb; // Use this for initialization void Start() { // Rigidbodyコンポーネント取得 rb = GetComponent<Rigidbody2D>(); //右上にボールを動かす rb.AddForce((transform.up + transfor</rigidbody2d>…
コツコツとUnityを使ったアプリ製作を続けてます。 uuc1h.hatenablog.jp 自分は全くのド素人から30歳でSEに転職し、プログラムを覚えた。プログラムを覚えるために様々な入門書を読んだ。オススメな入門書は、やっぱりサンプルがついているタイプ。本の通り…
// 弾を撃つ間隔 public float shotDelay = 3.0f; // Use this for initialization IEnumerator Start () { rb = GetComponent<Rigidbody2D>(); while (true) { shot(); yield return new WaitForSeconds(shotDelay); } } private void shot() { // プレハブ生成 Instanti</rigidbody2d>…
// 移動速度 public float speed = 2.0f; // Rigidbody private Rigidbody2D rb; // Use this for initialization void Start () { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update () { // 移動 move(); } private void move() { r</rigidbody2d>…
// ジャンプの力 public float jumpPower = 40; // ジャンプ中判定 private bool isJump = false; // 接地判定 private bool isGround = false; // Update is called once per frame void FixedUpdate () { // Playerの移動速度、方向をセット setMoveDirect…
1.UI / Buttonオブジェクトを作成する。 2.作成したButtonオブジェクトに、Event Triggerコンポーネントをセットする。 3.スクリプトは下記の通り。 public class Controller : MonoBehaviour { // 移動速度 public float moveSpeed = 3.0f; // 変数用移動速…
ColliderコンポーネントのIsTriggerチェックは外しておく。 // コライダーとの接触判定 private void OnCollisionEnter(Collision other) { if(other.gameObject.tag == "Controller") { Destroy(gameObject); Destroy(other.gameObject); } }
AudioSourceコンポーネントをアタッチし、AudioClipにアタッチしておく。 private AudioSource shotSound; void Start () { shotSound = GetComponent<AudioSource>(); } void shot() { shotSound.Play(); }</audiosource>
Main CameraのAudio Sourceコンポーネントに、オーディオソースをアタッチする。・Loopにチェックを入れる。・Play On Awakeにチェックを入れる。
public float lifeTime = 3.0f; void Start () { Destroy(gameObject, lifeTime); }
void Clamp() { // 画面左下のワールド座標をビューポートから取得 Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0)); // 画面右上のワールド座標をビューポートから取得 Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1,…
public class GameManager : MonoBehaviour { public Text time; public Text highTime; private int seconds; private void Start() { StartCoroutine(CountTime()); } // Update is called once per frame void Update () { time.text = "時間:" + second…
unityroomにあげる用のゲームを作り始めた。ちなみに前回unityroomに投稿したゲームは、閲覧数が100を超えてた。作ったゲームが実際に遊んでもらっていることが分かったので、非常にうれしい。 赤いボールからひたすら逃げろ | 無料ゲーム投稿サイト unityro…
public GameObject bullet; // Update is called once per frame void Update () { if(Input.GetMouseButtonDown(0)) { shot(); } } void shot() { Instantiate(bullet, transform.position, transform.rotation); } ちなみに、弾の方のスクリプトは以下。 p…
public float speed = 10; Rigidbody rb; void Start () { rb = GetComponent<Rigidbody>(); } // Update is called once per frame void Update () { float x = Input.GetAxisRaw("Horizontal"); float y = Input.GetAxisRaw("Vertical"); Vector2 direction = new Vec</rigidbody>…
>|cs| // 現在のシーン番号を取得 int sceneIndex = SceneManager.GetActiveScene().buildIndex; // 現在のシーンを再読込する SceneManager.LoadScene(sceneIndex); ||
// ハイスコアを更新 if(PlayerPrefs.GetInt("HighScore") < allSeconds) { // ハイスコアの保存 PlayerPrefs.SetInt("HighScore", allSeconds); } // ハイスコアの呼び出し highScore.text = "HIGH SCORE:" + PlayerPrefs.GetInt("HighScore"); // 変更され…
Vector3 vector3; public void createEnemy() { vector3 = new Vector3(Random.Range(-5.0f, 5.0f), transform.position.y, transform.position.z); // Enemyを作成する GameObject enemy = (GameObject)Instantiate(enemyOrigin, vector3, Quaternion.ident…