リンゴキャッチのアプリを作成しました。
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";
}
}