code ソーシャル

Unityアプリ作成(4)

スポンサーリンク

簡易版インベーダーゲーム風のアプリを作成しました。

だんだんスクリプトが相互に関係するようになってきたので複雑になってきました。

担当を分けてスクリプトを書いている場合に重複したメソッドなどを作らなくていいように、初期時点で誰が、どういう名前でメソッドを作るのかを共有しておき、作成が進むにつれて追加されるものは随時スプレッドシートなどで更新されるようになっておくと、新たなメソッドが必要な際に、スプレッドを検索し、自分で作らずに既存のものを呼び出すだけで済むのでトラブルが減りそうです。

 

//playercontroller

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

public class PlayerController : MonoBehaviour
{
void Start()
{

}
public void LButtonDown()
{
transform.Translate(-3,0,0);
}
public void RButtonDown()
{
transform.Translate(3,0,0);
}

void Update()
{
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.Translate(-3,0,0);
}
if(Input.GetKeyDown(KeyCode.RightArrow))
{
transform.Translate(3,0,0);
}

}
}

//arrowcontroller

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

public class ArrowController : MonoBehaviour
{
GameObject player;

void Start()
{
this.player=GameObject.Find("player");
}

void Update()
{
transform.Translate(0,-0.1f,0);
if(transform.position.y < -5.0f)
{
Destroy(gameObject);
}

Vector2 p1=transform.position;
Vector2 p2=this.player.transform.position;
Vector2 dir=p1-p2;
float d=dir.magnitude;
float r1=0.5f;
float r2=1.0f;

if(d<r1+r2)
{
GameObject director= GameObject.Find("GameDirector");
director.GetComponent<GameDirector>().DecreaseHp();

Destroy(gameObject);
}

}
}

//arrowgenerator

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

public class ArrowGenerator : MonoBehaviour
{
public GameObject arrowPrefab;
float span=1.0f;
float delta=0;

void Update()
{
this.delta +=Time.deltaTime;
if(this.delta>this.span)
{
this.delta=0;
GameObject go=Instantiate(arrowPrefab) as GameObject;
int px=Random.Range(-6,7);
go.transform.position=new Vector3(px, 7, 0);
}
}
}

//gamedirector

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

public class GameDirector : MonoBehaviour
{
GameObject hpGauge;
void Start()
{
this.hpGauge=GameObject.Find("hpGauge");
}

public void DecreaseHp()
{
this.hpGauge.GetComponent<Image>().fillAmount -= 0.1f;
}
}

人気の記事

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.