MyBotのセット④(MyBotアイコンの作成)





選択したBotのアイコンを表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetBot : MonoBehaviour
{
private GameObject target;
public GameObject[] myBotsPrefab;
private int num = 0;
public AudioClip selectSound;
public AudioClip NGSound;
public Material NGMark;
// ★追加
public GameObject[] botIcons;
// ★追加
private void Start()
{
for (int i = 0; i < botIcons.Length; i++)
{
if (i == num)
{
botIcons[i].SetActive(true);
}
else
{
botIcons[i].SetActive(false);
}
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
num = (num + 1) % myBotsPrefab.Length;
AudioSource.PlayClipAtPoint(selectSound, Camera.main.transform.position);
// ★追加
// 同じ処理をBotアイコンの数だけ繰り返す。
for (int i = 0; i < botIcons.Length; i++)
{
if (i == num)
{
botIcons[i].SetActive(true); // numと同じ数値のアイコンを表示
}
else
{
botIcons[i].SetActive(false); // それ以外は非表示
}
}
}
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);
target.tag = "NG";
target.GetComponent<MeshRenderer>().material = NGMark;
}
else
{
AudioSource.PlayClipAtPoint(NGSound, Camera.main.transform.position);
}
}
}
}
}


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




選択したBotのアイコンを表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetBot : MonoBehaviour
{
private GameObject target;
public GameObject[] myBotsPrefab;
private int num = 0;
public AudioClip selectSound;
public AudioClip NGSound;
public Material NGMark;
// ★追加
public GameObject[] botIcons;
// ★追加
private void Start()
{
for (int i = 0; i < botIcons.Length; i++)
{
if (i == num)
{
botIcons[i].SetActive(true);
}
else
{
botIcons[i].SetActive(false);
}
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
num = (num + 1) % myBotsPrefab.Length;
AudioSource.PlayClipAtPoint(selectSound, Camera.main.transform.position);
// ★追加
// 同じ処理をBotアイコンの数だけ繰り返す。
for (int i = 0; i < botIcons.Length; i++)
{
if (i == num)
{
botIcons[i].SetActive(true); // numと同じ数値のアイコンを表示
}
else
{
botIcons[i].SetActive(false); // それ以外は非表示
}
}
}
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);
target.tag = "NG";
target.GetComponent<MeshRenderer>().material = NGMark;
}
else
{
AudioSource.PlayClipAtPoint(NGSound, Camera.main.transform.position);
}
}
}
}
}


MyBotのセット④(MyBotアイコンの作成)