弾切れの発生②(ショットパワーを表示する)
![Acd8b183 278a 4440 ab35 d20853ca05e4](https://codegenius.org/uploads/slide/image/5276/acd8b183-278a-4440-ab35-d20853ca05e4.jpeg)
![4cbaf13e 1db8 4323 b477 1b8c72f574a5](https://codegenius.org/uploads/slide/image/5277/4cbaf13e-1db8-4323-b477-1b8c72f574a5.jpeg)
ショットパワー残量の表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(パワー残量の表示)
using UnityEngine.UI;
public class FireMissile : MonoBehaviour
{
public GameObject missilePrefab;
public float missileSpeed;
public AudioClip fireSound;
private int timeCount;
private int maxPower = 100;
private int shotPower;
// ★追加(パワー残量の表示)
public Slider powerSlider;
private void Start()
{
shotPower = maxPower;
// ★追加(パワー残量の表示)
powerSlider.maxValue = maxPower;
powerSlider.value = shotPower;
}
void Update()
{
timeCount += 1;
if (Input.GetButton("Jump"))
{
if(shotPower <= 0)
{
return;
}
shotPower -= 1;
// ★追加(パワー残量の表示)
powerSlider.value = shotPower;
if (timeCount % 5 == 0)
{
GameObject missile = Instantiate(missilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * missileSpeed);
AudioSource.PlayClipAtPoint(fireSound, transform.position);
Destroy(missile, 2.0f);
}
}
}
}
![5cc555b5 51c0 4105 8bc7 c800e700312c](https://codegenius.org/uploads/slide/image/5278/5cc555b5-51c0-4105-8bc7-c800e700312c.jpeg)
![918ab9c5 966b 4f73 b161 a172a4d837fc](https://codegenius.org/uploads/slide/image/5279/918ab9c5-966b-4f73-b161-a172a4d837fc.jpeg)
【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る![Acd8b183 278a 4440 ab35 d20853ca05e4](https://codegenius.org/uploads/slide/image/5276/acd8b183-278a-4440-ab35-d20853ca05e4.jpeg)
![4cbaf13e 1db8 4323 b477 1b8c72f574a5](https://codegenius.org/uploads/slide/image/5277/4cbaf13e-1db8-4323-b477-1b8c72f574a5.jpeg)
ショットパワー残量の表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(パワー残量の表示)
using UnityEngine.UI;
public class FireMissile : MonoBehaviour
{
public GameObject missilePrefab;
public float missileSpeed;
public AudioClip fireSound;
private int timeCount;
private int maxPower = 100;
private int shotPower;
// ★追加(パワー残量の表示)
public Slider powerSlider;
private void Start()
{
shotPower = maxPower;
// ★追加(パワー残量の表示)
powerSlider.maxValue = maxPower;
powerSlider.value = shotPower;
}
void Update()
{
timeCount += 1;
if (Input.GetButton("Jump"))
{
if(shotPower <= 0)
{
return;
}
shotPower -= 1;
// ★追加(パワー残量の表示)
powerSlider.value = shotPower;
if (timeCount % 5 == 0)
{
GameObject missile = Instantiate(missilePrefab, transform.position, Quaternion.identity);
Rigidbody missileRb = missile.GetComponent<Rigidbody>();
missileRb.AddForce(transform.forward * missileSpeed);
AudioSource.PlayClipAtPoint(fireSound, transform.position);
Destroy(missile, 2.0f);
}
}
}
}
![5cc555b5 51c0 4105 8bc7 c800e700312c](https://codegenius.org/uploads/slide/image/5278/5cc555b5-51c0-4105-8bc7-c800e700312c.jpeg)
![918ab9c5 966b 4f73 b161 a172a4d837fc](https://codegenius.org/uploads/slide/image/5279/918ab9c5-966b-4f73-b161-a172a4d837fc.jpeg)
弾切れの発生②(ショットパワーを表示する)