敵ロボットをターンさせる1


敵を左にターンさせる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTurn : MonoBehaviour
{
private float maxDistance = 0.5f;
private string tagName;
void Update()
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * 0.5f, Color.red);
if(Physics.Raycast(ray, out hit, maxDistance))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
// switch文の書き方
switch(tagName)
{
case "RedPillar_L":
transform.root.localRotation = Quaternion.Euler(0, transform.root.eulerAngles.y + 270, 0);
break;
}
}
}
}







【2019版】TowerD I(基礎/全10回)
1 | 敵ロボットの作成&前進 |
2 | 敵ロボットをターンさせる1 |
3 | 敵ロボットをターンさせる2 |
4 | 敵ロボットにHPをつける |
5 | ロボットを生み出す装置を作る |
6 | マイロボットの作成1 |
7 | マイロボットにライフタイムを設定する |
8 | マイロボットの作成2 |
9 | ★チェックポイント |
10 | ★チャレンジ |


敵を左にターンさせる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTurn : MonoBehaviour
{
private float maxDistance = 0.5f;
private string tagName;
void Update()
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * 0.5f, Color.red);
if(Physics.Raycast(ray, out hit, maxDistance))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
// switch文の書き方
switch(tagName)
{
case "RedPillar_L":
transform.root.localRotation = Quaternion.Euler(0, transform.root.eulerAngles.y + 270, 0);
break;
}
}
}
}







敵ロボットをターンさせる1