code ソーシャル

Unityアプリ作成(7)

スポンサーリンク

リンゴキャッチのアプリを作成しました。

iphoneに画像録画だけでなく、音声付きにもできることにも撮影後に気付きました。

次回は音声付きにしようと思います。

サンプル素材を今まで使っていたのですが、今後オリジナル作品を作るためにオリジナル素材の作成方法も習得しておく必要がありそうです。

 

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

public class BasketController : MonoBehaviour
{
public AudioClip appleSE;
public AudioClip bombSE;
AudioSource aud;
GameObject director;

void Start()
{
this.aud = GetComponent<AudioSource>();
this.director = GameObject.Find("GameDirector");
}

void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "Apple")
{
this.director.GetComponent<GameDirector>().GetApple();
this.aud.PlayOneShot(this.appleSE);
}
else
{
this.director.GetComponent<GameDirector>().GetBomb();
this.aud.PlayOneShot(this.bombSE);
}
Destroy(collider.gameObject);
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
float x = Mathf.RoundToInt(hit.point.x);
float z = Mathf.RoundToInt(hit.point.z);
transform.position = new Vector3(x, 0, z);
}
}
}
}

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

public class ItemController : MonoBehaviour
{
public float dropSpeed = -0.03f;

// Update is called once per frame
void Update()
{
transform.Translate(0, this.dropSpeed, 0);
if (transform.position.y < -1.0f)
{
Destroy(gameObject);
}
}
}

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

public class ItemGenerator : MonoBehaviour
{
public GameObject applePrefab;
public GameObject bombPrefab;
float span = 1.0f;
float delta = 0;
int ratio = 2;
float speed = -0.03f;

public void SetParameter(float span,float speed,int ratio)
{
this.span = span;
this.speed = speed;
this.ratio = ratio;
}

void Update()
{
this.delta += Time.deltaTime;
if(this.delta > this.span)
{
this.delta = 0;
GameObject item;
int dice = Random.Range(1, 11);
if (dice <= this.ratio)
{
item = Instantiate(bombPrefab) as GameObject;
}
else
{
item = Instantiate(applePrefab) as GameObject;
}

float x = Random.Range(-1, 2);
float z = Random.Range(-1, 2);
item.transform.position = new Vector3(x, 4, z);
item.GetComponent<ItemController>().dropSpeed = this.speed;
}
}
}

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

public class GameDirector : MonoBehaviour
{
GameObject timerText;
GameObject pointText;

float time = 30.0f;
int point = 0;
GameObject generator;

public void GetApple()
{
this.point += 100;
}

public void GetBomb()
{
this.point /= 2;
}

void Start()
{
this.generator = GameObject.Find("ItemGenerator");
this.timerText = GameObject.Find("Time");
this.pointText = GameObject.Find("Point");
}

void Update()
{
this.time -= Time.deltaTime;

if (this.time < 0)
{
this.time = 0;
this.generator.GetComponent<ItemGenerator>().SetParameter(10000.0f, 0, 0);
}
else if(0 <= this.time && this.time < 5)
{
this.generator.GetComponent<ItemGenerator>().SetParameter(0.7f, -0.04f, 3);
}
else if(5 <= this.time && this.time < 12)
{
this.generator.GetComponent<ItemGenerator>().SetParameter(0.5f, -0.05f, 6);
}
else if (12 <= this.time && this.time < 23)
{
this.generator.GetComponent<ItemGenerator>().SetParameter(0.8f, -0.04f, 4);
}
else if (23 <= this.time && this.time < 30)
{
this.generator.GetComponent<ItemGenerator>().SetParameter(1.0f, -0.03f, 2);
}

this.timerText.GetComponent<Text>().text = this.time.ToString("F1");
this.pointText.GetComponent<Text>().text = this.point.ToString() + "point";
}
}

人気の記事

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.