//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つのアニメーションで表示したもの。