code ソーシャル

Unityアプリcodetips(56)

スポンサーリンク

//tips

stage追加処理と微調整継続

//子要素にしたspriteが見えない時

Enemyの子要素にしたスプライトが見えない時は、spriteのスケールとrotationを確認する。

Rotationのx.y.zの値に注意して、変化させてみる。

//Scene追加の際に忘れないこと

Sceneを追加する際にgoalcontrollerのstageNoをしっかり変更する。

Goal時に新たなclearstageをplayerprefsでsetしているので忘れない。

さらにbuiltsettingでシーンをbuildパッケージの中に追加する。

追加しないとシーン移行できないので。

//Unity asset storeで購入したパッケージ

Unity asset storeで購入したパッケージはpackage managerに追加されており、そこからunityへpackageのダウンロード・インポートを行うことができる。

事前にダウンロードpackageの容量も確認しておく、ダウンロード・インポート完了までにかなりの時間がかかる場合がある。

350MBと650MBのもので2時間半程度かかった。

//enemyの種類増加に伴うスクリプトの設定

衝突後のFadeエフェクトの実行設定やanimationのtrigger設定を新たにする必要がある。

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

public class EnemyBruteY : MonoBehaviour
{
[SerializeField] GameObject Fade;

GameObject Player;
Animator anim;

Vector3 MOVEX = new Vector3(1.0f, 0, 0);
Vector3 MOVEY = new Vector3(0, 1.0f, 0);
Vector3 MOVEZ = new Vector3(0, 0, 1.0f);

Vector3 target; // 入力受付時、移動後の位置を算出して保存

private int count = 0;

void Start()
{
target = transform.position;

this.Player = GameObject.Find("Player");

}

void Update()
{
if (Input.anyKeyDown)
{
count++;
//anim = GetComponent<Animator>();
//this.anim.SetTrigger("walk");

if (count == 1)
{
target = transform.position - MOVEZ;
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

//transform.rotation = Quaternion.Euler(0, 270, 0);

}

if (count == 2)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position - MOVEZ;

}

if (count == 3)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position - MOVEY;

transform.rotation = Quaternion.Euler(0, 90, 0);

}
if (count == 4)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position + MOVEY;
//count = 0;

}

if (count == 5)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position - MOVEZ;

}

if (count == 6)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position + MOVEX;

transform.rotation = Quaternion.Euler(0, 90, 0);

}
if (count == 7)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("walk");

target = transform.position - MOVEX;
transform.rotation = Quaternion.Euler(0, 270, 0);
//count = 0;

}
if (count >= 8)
{
anim = GetComponent<Animator>();
this.anim.SetTrigger("idle");
//count = 0;

}

}

Move();

Vector3 p1 = transform.position;
Vector3 p2 = this.Player.transform.position;

if (p1 == p2)
{
Fadeover();

if (Player != null)
{
//Camera.main.transform.SetParent(null);
//subCamera.transform.SetParent(null);
//Player.transform.DetachChildren();

//this.Player.SetActive(false);

//Destroy(Player);
Invoke("Over", 1);

}
}

}
void Move()
{
this.transform.position = target;
}
void Over()
{
SceneManager.LoadScene("GameOver");
}
void Fadeover()
{
Fade.SetActive(true);
}

}

座標移動を伴いanimationの設定を行なっている場合、設定されている座標位置に戻るので注意。

Enemyやゴールの移動後に同じモーションをつけていたら元の場所に戻る。

新しいanimatorを作成し、それに新たなクリップをつけることで対応する。

下記はゴールの目標sphereを2つのアニメーションで表示したもの。

 

人気の記事

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.