ビームラベルの実装


ビーム名の表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(ビームラベル)
using TMPro;
public class ShotBeam : MonoBehaviour
{
public GameObject laserGun;
public GameObject[] beamPrefabs;
public AudioClip shotSound;
public float shotSpeed;
private int num = 0;
public AudioClip changeSound;
// ★追加(ビームラベル)
public TextMeshProUGUI beamLabel;
// ★追加(ビームラベル)
private void Start()
{
beamLabel.text = "" + beamPrefabs[num].name;
}
void Update()
{
if (Input.GetMouseButtonDown(1))
{
num = (num + 1) % beamPrefabs.Length;
AudioSource.PlayClipAtPoint(changeSound, Camera.main.transform.position);
// ★追加(ビームラベル)
beamLabel.text = "" + beamPrefabs[num].name;
}
if (Input.GetMouseButtonDown(0))
{
GameObject beam = Instantiate(beamPrefabs[num], transform.position, laserGun.transform.rotation);
Rigidbody beamRb = beam.GetComponent<Rigidbody>();
beamRb.AddForce(transform.forward * shotSpeed);
AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position);
}
}
}


【2021版】X_Mission(全34回)
他のコースを見る

ビーム名の表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(ビームラベル)
using TMPro;
public class ShotBeam : MonoBehaviour
{
public GameObject laserGun;
public GameObject[] beamPrefabs;
public AudioClip shotSound;
public float shotSpeed;
private int num = 0;
public AudioClip changeSound;
// ★追加(ビームラベル)
public TextMeshProUGUI beamLabel;
// ★追加(ビームラベル)
private void Start()
{
beamLabel.text = "" + beamPrefabs[num].name;
}
void Update()
{
if (Input.GetMouseButtonDown(1))
{
num = (num + 1) % beamPrefabs.Length;
AudioSource.PlayClipAtPoint(changeSound, Camera.main.transform.position);
// ★追加(ビームラベル)
beamLabel.text = "" + beamPrefabs[num].name;
}
if (Input.GetMouseButtonDown(0))
{
GameObject beam = Instantiate(beamPrefabs[num], transform.position, laserGun.transform.rotation);
Rigidbody beamRb = beam.GetComponent<Rigidbody>();
beamRb.AddForce(transform.forward * shotSpeed);
AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position);
}
}
}


ビームラベルの実装