ARシューティングゲームの開発





敵を動かす(直線)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
void Update()
{
transform.Translate(new Vector3(0, 0.1f, 0) * Time.deltaTime, Space.World);
}
}



敵を動かす(L字型)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove2 : MonoBehaviour
{
private float x;
private float z;
private float speed;
void Start()
{
StartCoroutine(MoveL());
}
void Update()
{
transform.Translate(new Vector3(x, 0, z) * speed * Time.deltaTime, Space.World);
}
// 敵が途中で右方向に移動
private IEnumerator MoveL()
{
// 最初はZ方向に移動
x = 0;
z = -0.1f;
speed = 1;
// 2秒経過後に
yield return new WaitForSeconds(2f);
// 右方向(X方向)に移動
x = 0.1f;
z = 0;
speed = 1.2f; // スピードも少しアップ
}
}



敵を動かす(上下往復)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove3 : MonoBehaviour
{
private float y;
private float z;
private float speed;
private void Start()
{
StartCoroutine(DMove());
}
private void Update()
{
transform.Translate(new Vector3(0, y, z) * speed * Time.deltaTime, Space.World);
}
private IEnumerator DMove()
{
// 繰り返し文の追加(ポイント)
for (int i = 0; i < 3; i++)
{
y = 0.1f;
z = -0.1f;
speed = 1f;
yield return new WaitForSeconds(1f);
y = -0.1f;
z = -0.1f;
speed = 1f;
yield return new WaitForSeconds(1f);
}
}
}


【2022版】AR_Project(全9回)
1 | キャラクターをAR鑑賞する |
2 | ★チャレンジ課題 |
3 | ARシューティングゲームの開発 |
4 | ★チャレンジ課題 |
5 | 敵の製造装置を作る |
6 | 敵を破壊する |
7 | オリジナルのカーソルを作成する |
8 | カウンターを作成する |
9 | ★チャレンジ課題 |





敵を動かす(直線)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
void Update()
{
transform.Translate(new Vector3(0, 0.1f, 0) * Time.deltaTime, Space.World);
}
}



敵を動かす(L字型)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove2 : MonoBehaviour
{
private float x;
private float z;
private float speed;
void Start()
{
StartCoroutine(MoveL());
}
void Update()
{
transform.Translate(new Vector3(x, 0, z) * speed * Time.deltaTime, Space.World);
}
// 敵が途中で右方向に移動
private IEnumerator MoveL()
{
// 最初はZ方向に移動
x = 0;
z = -0.1f;
speed = 1;
// 2秒経過後に
yield return new WaitForSeconds(2f);
// 右方向(X方向)に移動
x = 0.1f;
z = 0;
speed = 1.2f; // スピードも少しアップ
}
}



敵を動かす(上下往復)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove3 : MonoBehaviour
{
private float y;
private float z;
private float speed;
private void Start()
{
StartCoroutine(DMove());
}
private void Update()
{
transform.Translate(new Vector3(0, y, z) * speed * Time.deltaTime, Space.World);
}
private IEnumerator DMove()
{
// 繰り返し文の追加(ポイント)
for (int i = 0; i < 3; i++)
{
y = 0.1f;
z = -0.1f;
speed = 1f;
yield return new WaitForSeconds(1f);
y = -0.1f;
z = -0.1f;
speed = 1f;
yield return new WaitForSeconds(1f);
}
}
}


ARシューティングゲームの開発