MyBotのセット②(同じ場所には設置不可)


同じ場所には設置できないようにする
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;
// ★追加(NGの設定)
public AudioClip NGSound;
public Material NGMark;
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);
// ★追加(NGの設定)
target.tag = "NG"; // TagをNGに変更する
target.GetComponent<MeshRenderer>().material = NGMark; // MaterialをNGマークに変更する
}
// ★追加(NGの設定)
else
{
AudioSource.PlayClipAtPoint(NGSound, Camera.main.transform.position);
}
}
}
}
}




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

同じ場所には設置できないようにする
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;
// ★追加(NGの設定)
public AudioClip NGSound;
public Material NGMark;
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);
// ★追加(NGの設定)
target.tag = "NG"; // TagをNGに変更する
target.GetComponent<MeshRenderer>().material = NGMark; // MaterialをNGマークに変更する
}
// ★追加(NGの設定)
else
{
AudioSource.PlayClipAtPoint(NGSound, Camera.main.transform.position);
}
}
}
}
}




MyBotのセット②(同じ場所には設置不可)