MyBotのセット①


MyBotのセレクト&セット
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetBot : MonoBehaviour
{
private GameObject target;
// MyBotのセレクト機能
public GameObject[] myBotsPrefab;
private int num = 0;
public AudioClip selectSound;
void Update()
{
// 「マウスの右クリック」でボットを選択する。
if(Input.GetKeyDown(KeyCode.Mouse1))
{
num = (num + 1) % myBotsPrefab.Length;
AudioSource.PlayClipAtPoint(selectSound, Camera.main.transform.position);
}
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
target = hit.collider.gameObject;
// 「マウスの左クリック」でボットをセットする。
if(Input.GetKeyDown(KeyCode.Mouse0))
{
if(target.tag == "Block")
{
// ブロックの位置にボットをセットする。
GameObject bot = Instantiate(myBotsPrefab[num], target.transform.position, Quaternion.identity);
}
}
}
}
}




【2021版】TowerD Ⅱ(全17回)
他のコースを見る

MyBotのセレクト&セット
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetBot : MonoBehaviour
{
private GameObject target;
// MyBotのセレクト機能
public GameObject[] myBotsPrefab;
private int num = 0;
public AudioClip selectSound;
void Update()
{
// 「マウスの右クリック」でボットを選択する。
if(Input.GetKeyDown(KeyCode.Mouse1))
{
num = (num + 1) % myBotsPrefab.Length;
AudioSource.PlayClipAtPoint(selectSound, Camera.main.transform.position);
}
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
target = hit.collider.gameObject;
// 「マウスの左クリック」でボットをセットする。
if(Input.GetKeyDown(KeyCode.Mouse0))
{
if(target.tag == "Block")
{
// ブロックの位置にボットをセットする。
GameObject bot = Instantiate(myBotsPrefab[num], target.transform.position, Quaternion.identity);
}
}
}
}
}




MyBotのセット①