★オリジナル敵ロボットの作成
移動速度の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
public float MoveSpeed { get; set; }
private float maxDis = 0.75f;
private string tagName;
private void Start()
{
// ★追加
// 敵ロボットごとに移動速度を変える(名前で区別する・ポイント)
string name = this.gameObject.name;
switch (name)
{
case "EnemyBot_A(Clone)": // 名前は一言一句正確に!
MoveSpeed = 5;
break;
case "EnemyBot_B(Clone)":
MoveSpeed = 10;
break;
case "EnemyBot_C(Clone)":
MoveSpeed = 3;
break;
case "EnemyBot_D(Clone)":
MoveSpeed = 1;
break;
}
}
void Update()
{
transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * maxDis, Color.red);
if (Physics.Raycast(ray, out hit, maxDis))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
switch (tagName)
{
case "Right":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
break;
case "Left":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
break;
}
}
}
}
耐久力の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBot_B : EnemyBase
{
private void Start()
{
HP = 3;
}
}
【2021版】TowerD Ⅱ(全17回)
他のコースを見る移動速度の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
public float MoveSpeed { get; set; }
private float maxDis = 0.75f;
private string tagName;
private void Start()
{
// ★追加
// 敵ロボットごとに移動速度を変える(名前で区別する・ポイント)
string name = this.gameObject.name;
switch (name)
{
case "EnemyBot_A(Clone)": // 名前は一言一句正確に!
MoveSpeed = 5;
break;
case "EnemyBot_B(Clone)":
MoveSpeed = 10;
break;
case "EnemyBot_C(Clone)":
MoveSpeed = 3;
break;
case "EnemyBot_D(Clone)":
MoveSpeed = 1;
break;
}
}
void Update()
{
transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * maxDis, Color.red);
if (Physics.Raycast(ray, out hit, maxDis))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
switch (tagName)
{
case "Right":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
break;
case "Left":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
break;
}
}
}
}
耐久力の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBot_B : EnemyBase
{
private void Start()
{
HP = 3;
}
}
★オリジナル敵ロボットの作成