ロケットランチャーの「残弾数」と「回復アイテム数」を画面に表示する
ShotRocketの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class ShotRocket : MonoBehaviour {
public GameObject rocketPrefab;
public AudioClip shotSound;
public float rocketSpeed;
private float timeBetweenShot = 1.2f;
private float timer;
public static int shotRocketCount = 30;
public static int RocketItemCount = 0;
// ★追加
public Text rocketNum;
public Text rocketItemNum;
// ★追加
void Start(){
rocketNum.color = Color.white;
rocketNum.text = shotRocketCount + "/30";
rocketItemNum.text = "× " + RocketItemCount;
}
void Update () {
timer += Time.deltaTime;
if (Input.GetKeyDown (KeyCode.Space) && timer > timeBetweenShot) {
if (shotRocketCount < 1) {
return;
}
shotRocketCount -= 1;
// ★追加
rocketNum.text = shotRocketCount + "/30";
rocketItemNum.text = "× " + RocketItemCount;
timer = 0.0f;
GameObject rocket = (GameObject)Instantiate (rocketPrefab, transform.position, Quaternion.Euler (transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
Rigidbody rocketRb = rocket.GetComponent<Rigidbody> ();
rocketRb.AddForce (transform.forward * rocketSpeed);
AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position);
Destroy (rocket, 3.0f);
}
}
public void AddRocketItem(int amount){
RocketItemCount += amount;
print ("ロケット弾の回復の権利" + RocketItemCount + "回");
// ★追加
rocketItemNum.text = "× " + RocketItemCount;
}
}
EscapeCombat(メモ)
他のコースを見るShotRocketの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class ShotRocket : MonoBehaviour {
public GameObject rocketPrefab;
public AudioClip shotSound;
public float rocketSpeed;
private float timeBetweenShot = 1.2f;
private float timer;
public static int shotRocketCount = 30;
public static int RocketItemCount = 0;
// ★追加
public Text rocketNum;
public Text rocketItemNum;
// ★追加
void Start(){
rocketNum.color = Color.white;
rocketNum.text = shotRocketCount + "/30";
rocketItemNum.text = "× " + RocketItemCount;
}
void Update () {
timer += Time.deltaTime;
if (Input.GetKeyDown (KeyCode.Space) && timer > timeBetweenShot) {
if (shotRocketCount < 1) {
return;
}
shotRocketCount -= 1;
// ★追加
rocketNum.text = shotRocketCount + "/30";
rocketItemNum.text = "× " + RocketItemCount;
timer = 0.0f;
GameObject rocket = (GameObject)Instantiate (rocketPrefab, transform.position, Quaternion.Euler (transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
Rigidbody rocketRb = rocket.GetComponent<Rigidbody> ();
rocketRb.AddForce (transform.forward * rocketSpeed);
AudioSource.PlayClipAtPoint (shotSound, Camera.main.transform.position);
Destroy (rocket, 3.0f);
}
}
public void AddRocketItem(int amount){
RocketItemCount += amount;
print ("ロケット弾の回復の権利" + RocketItemCount + "回");
// ★追加
rocketItemNum.text = "× " + RocketItemCount;
}
}
ロケットランチャーの「残弾数」と「回復アイテム数」を画面に表示する