Stop&Go弾の作成
![56cc911b 6077 4289 8897 7268e082c343](https://codegenius.org/uploads/slide/image/5243/56cc911b-6077-4289-8897-7268e082c343.jpeg)
![89069975 f50a 4c1d af95 39bc3d72b14e](https://codegenius.org/uploads/slide/image/5244/89069975-f50a-4c1d-af95-39bc3d72b14e.jpeg)
![1c69f5cc c7ca 4e37 9d26 9668e9748827](https://codegenius.org/uploads/slide/image/5245/1c69f5cc-c7ca-4e37-9d26-9668e9748827.jpeg)
![707a887b 9d4d 4431 b18d 7c3f6f4bfa2e](https://codegenius.org/uploads/slide/image/5246/707a887b-9d4d-4431-b18d-7c3f6f4bfa2e.jpeg)
Stop&Go弾
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopGo : MonoBehaviour
{
public float startSpeed_Min = 60;
public float startSpeed_Max = 300;
public float nextSpeed;
private Rigidbody rb;
private GameObject target;
private float timeCount = 0;
public float stopTime = 3; // 弾が生成後、何秒したら停止するか?
private float stopTimeCount = 0;
private float nextStartTime = 2; // 弾が停止後、何秒したら動き出すか?
private bool stopKey = false;
void Start()
{
rb = GetComponent<Rigidbody>();
// 初速はランダムにする。
rb.AddForce(-transform.forward * Random.Range(startSpeed_Min, startSpeed_Max));
target = GameObject.Find("Player");
}
void Update()
{
timeCount += Time.deltaTime;
if(timeCount >= stopTime && !stopKey)
{
stopTimeCount += Time.deltaTime;
rb.velocity = Vector3.zero; // 弾の速度を0にする=弾を停止させる。
// 弾の色を変える
GetComponent<MeshRenderer>().material.color = Color.white;
if(stopTimeCount >= nextStartTime)
{
if(target != null)
{
// プレーヤーの方向に向きを変える。
this.gameObject.transform.LookAt(target.transform.position);
}
rb.AddForce(transform.forward * nextSpeed);
stopKey = true;
}
}
}
}
![1ba9d8dd a128 4ff7 95b9 a1197f404aa9](https://codegenius.org/uploads/slide/image/5247/1ba9d8dd-a128-4ff7-95b9-a1197f404aa9.jpeg)
![C412ba7f d191 45b0 a2e6 2775435dd74a](https://codegenius.org/uploads/slide/image/5248/c412ba7f-d191-45b0-a2e6-2775435dd74a.jpeg)
![1e9d1aa8 248c 4da5 b6cc 82305d7e21e9](https://codegenius.org/uploads/slide/image/5249/1e9d1aa8-248c-4da5-b6cc-82305d7e21e9.jpeg)
![8c9c36b1 5d8d 479c b384 06cace5ac687](https://codegenius.org/uploads/slide/image/5250/8c9c36b1-5d8d-479c-b384-06cace5ac687.jpeg)
![3d18fee9 5b32 40ff ba46 a9afde18048d](https://codegenius.org/uploads/slide/image/5251/3d18fee9-5b32-40ff-ba46-a9afde18048d.jpeg)
![358e8ffe 28b2 4605 9e8c e719f8719d96](https://codegenius.org/uploads/slide/image/5252/358e8ffe-28b2-4605-9e8c-e719f8719d96.jpeg)
製造装置
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gene_StopGo : MonoBehaviour
{
public GameObject stopGoPrefab;
private int timeCount;
void Update()
{
timeCount += 1;
if(timeCount % 100 == 0)
{
GameObject stopGo = Instantiate(stopGoPrefab, transform.position, Quaternion.identity);
Destroy(stopGo, 10f);
}
}
}
![2255ee86 763b 4a32 8535 00eb3cf32cba](https://codegenius.org/uploads/slide/image/5253/2255ee86-763b-4a32-8535-00eb3cf32cba.jpeg)
![Ea1b8ee6 3810 4935 81bd 133ab35f26de](https://codegenius.org/uploads/slide/image/5254/ea1b8ee6-3810-4935-81bd-133ab35f26de.jpeg)
![57f2ef09 0bf8 4038 bb0b 8cc96a989152](https://codegenius.org/uploads/slide/image/5255/57f2ef09-0bf8-4038-bb0b-8cc96a989152.jpeg)
【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る![56cc911b 6077 4289 8897 7268e082c343](https://codegenius.org/uploads/slide/image/5243/56cc911b-6077-4289-8897-7268e082c343.jpeg)
![89069975 f50a 4c1d af95 39bc3d72b14e](https://codegenius.org/uploads/slide/image/5244/89069975-f50a-4c1d-af95-39bc3d72b14e.jpeg)
![1c69f5cc c7ca 4e37 9d26 9668e9748827](https://codegenius.org/uploads/slide/image/5245/1c69f5cc-c7ca-4e37-9d26-9668e9748827.jpeg)
![707a887b 9d4d 4431 b18d 7c3f6f4bfa2e](https://codegenius.org/uploads/slide/image/5246/707a887b-9d4d-4431-b18d-7c3f6f4bfa2e.jpeg)
Stop&Go弾
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopGo : MonoBehaviour
{
public float startSpeed_Min = 60;
public float startSpeed_Max = 300;
public float nextSpeed;
private Rigidbody rb;
private GameObject target;
private float timeCount = 0;
public float stopTime = 3; // 弾が生成後、何秒したら停止するか?
private float stopTimeCount = 0;
private float nextStartTime = 2; // 弾が停止後、何秒したら動き出すか?
private bool stopKey = false;
void Start()
{
rb = GetComponent<Rigidbody>();
// 初速はランダムにする。
rb.AddForce(-transform.forward * Random.Range(startSpeed_Min, startSpeed_Max));
target = GameObject.Find("Player");
}
void Update()
{
timeCount += Time.deltaTime;
if(timeCount >= stopTime && !stopKey)
{
stopTimeCount += Time.deltaTime;
rb.velocity = Vector3.zero; // 弾の速度を0にする=弾を停止させる。
// 弾の色を変える
GetComponent<MeshRenderer>().material.color = Color.white;
if(stopTimeCount >= nextStartTime)
{
if(target != null)
{
// プレーヤーの方向に向きを変える。
this.gameObject.transform.LookAt(target.transform.position);
}
rb.AddForce(transform.forward * nextSpeed);
stopKey = true;
}
}
}
}
![1ba9d8dd a128 4ff7 95b9 a1197f404aa9](https://codegenius.org/uploads/slide/image/5247/1ba9d8dd-a128-4ff7-95b9-a1197f404aa9.jpeg)
![C412ba7f d191 45b0 a2e6 2775435dd74a](https://codegenius.org/uploads/slide/image/5248/c412ba7f-d191-45b0-a2e6-2775435dd74a.jpeg)
![1e9d1aa8 248c 4da5 b6cc 82305d7e21e9](https://codegenius.org/uploads/slide/image/5249/1e9d1aa8-248c-4da5-b6cc-82305d7e21e9.jpeg)
![8c9c36b1 5d8d 479c b384 06cace5ac687](https://codegenius.org/uploads/slide/image/5250/8c9c36b1-5d8d-479c-b384-06cace5ac687.jpeg)
![3d18fee9 5b32 40ff ba46 a9afde18048d](https://codegenius.org/uploads/slide/image/5251/3d18fee9-5b32-40ff-ba46-a9afde18048d.jpeg)
![358e8ffe 28b2 4605 9e8c e719f8719d96](https://codegenius.org/uploads/slide/image/5252/358e8ffe-28b2-4605-9e8c-e719f8719d96.jpeg)
製造装置
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gene_StopGo : MonoBehaviour
{
public GameObject stopGoPrefab;
private int timeCount;
void Update()
{
timeCount += 1;
if(timeCount % 100 == 0)
{
GameObject stopGo = Instantiate(stopGoPrefab, transform.position, Quaternion.identity);
Destroy(stopGo, 10f);
}
}
}
![2255ee86 763b 4a32 8535 00eb3cf32cba](https://codegenius.org/uploads/slide/image/5253/2255ee86-763b-4a32-8535-00eb3cf32cba.jpeg)
![Ea1b8ee6 3810 4935 81bd 133ab35f26de](https://codegenius.org/uploads/slide/image/5254/ea1b8ee6-3810-4935-81bd-133ab35f26de.jpeg)
![57f2ef09 0bf8 4038 bb0b 8cc96a989152](https://codegenius.org/uploads/slide/image/5255/57f2ef09-0bf8-4038-bb0b-8cc96a989152.jpeg)
Stop&Go弾の作成