code ソーシャル

Unityアプリ作成(8)

スポンサーリンク

坊主ゲームアプリを制作しておりますが、いろいろな機能を盛り込んでいくと、長編になりそうなので、分割して出します。

今回はアプリの骨格ができたので共有します。

 

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

public class OrbManager : MonoBehaviour
{
private GameObject gameManager;
// Start is called before the first frame update
void Start()
{
gameManager = GameObject.Find("GameManager");
}

// Update is called once per frame
void Update()
{

}
public void TouchOrb()
{
if (Input.GetMouseButton(0) == false)
{
return;
}
gameManager.GetComponent<GameManager>().GetOrb();
Destroy(this.gameObject);
}
}

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

using UnityEngine.UI;

public class TempleManager : MonoBehaviour
{
public Sprite[] templePicture = new Sprite[3];
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
public void SetTemplePicture(int level)
{
GetComponent<Image>().sprite = templePicture[level];
}
public void SetTempleScale(int score, int nextScore)
{
float scale = 0.5f + (((float)score / (float)nextScore) / 2.0f);
transform.localScale = new Vector3(scale, scale, 1.0f);
}

}

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

public class GameManager : MonoBehaviour
{
private const int MAX_ORB = 10;
private const int RESPAWN_TIME = 1;
private const int MAX_LEVEL = 2;

public GameObject orbPrefab;
public GameObject smokePrefab;
public GameObject kusudamaPrefab;
public GameObject canvasGame;
public GameObject textScore;
public GameObject imageTemple;

private int score = 0;
private int nextScore = 10;

private int currentOrb = 0;
private int templeLevel = 0;

private DateTime lastDateTime;

private int[] nextScoreTable = new int[] { 10, 10, 10 };

// Start is called before the first frame update
void Start()
{
currentOrb = 10;

for(int i = 0; i < currentOrb; i++)
{
CreateOrb();
}
lastDateTime = DateTime.UtcNow;

nextScore = nextScoreTable[templeLevel];
imageTemple.GetComponent<TempleManager>().SetTemplePicture(templeLevel);
imageTemple.GetComponent<TempleManager>().SetTempleScale(score, nextScore);

RefreshScoreText();
}

// Update is called once per frame
void Update()
{
if(currentOrb < MAX_ORB)
{
TimeSpan timeSpan = DateTime.UtcNow - lastDateTime;
if(timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
{
while(timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
{
CreateNewOrb();
timeSpan -= TimeSpan.FromSeconds(RESPAWN_TIME);
}
}
}

}

public void CreateNewOrb()
{
lastDateTime = DateTime.UtcNow;
if(currentOrb >= MAX_ORB)
{
return;
}
CreateOrb();
currentOrb++;

}

public void CreateOrb()
{
GameObject orb = (GameObject)Instantiate(orbPrefab);
orb.transform.SetParent(canvasGame.transform, false);
orb.transform.localPosition = new Vector3(UnityEngine.Random.Range(-300.0f, 300.0f), UnityEngine.Random.Range(-140.0f, -500.0f));
}
public void GetOrb()
{
score += 1;

if(score > nextScore)
{
score = nextScore;
}
TempleLevelUp();

RefreshScoreText();

imageTemple.GetComponent<TempleManager>().SetTempleScale(score, nextScore);

if((score == nextScore) && (templeLevel == MAX_LEVEL))
{
ClearEffect();
}

currentOrb--;
}

void RefreshScoreText()
{
textScore.GetComponent<Text>().text = "徳:" + score + "/" + nextScore;
}

void TempleLevelUp()
{
if(score >= nextScore)
{
if(templeLevel < MAX_LEVEL)
{
templeLevel++;
score = 0;

TempleLevelUpEffect();

nextScore = nextScoreTable[templeLevel];
imageTemple.GetComponent<TempleManager>().SetTemplePicture(templeLevel);
}
}
}
void TempleLevelUpEffect()
{
GameObject smoke = (GameObject)Instantiate(smokePrefab);
smoke.transform.SetParent(canvasGame.transform, false);
smoke.transform.SetSiblingIndex(2);

Destroy(smoke, 0.5f);
}
void ClearEffect()
{
GameObject kusudama = (GameObject)Instantiate(kusudamaPrefab);
kusudama.transform.SetParent(canvasGame.transform, false);
}

}

 

 

人気の記事

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.