攻撃力の強化③(オプションアイテム)
Optionのオン・オフの管理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OptionController : MonoBehaviour
{
public GameObject[] options;
private bool moveOK = false;
private Vector3 playerPos;
private List<Vector3> playerPosRecord = new List<Vector3>();
// ★追加
private int optionCount = 0;
void Start()
{
playerPos = transform.position;
for (int i = 0; i < 40; i++)
{
playerPosRecord.Add(playerPos);
}
// ★追加
// ゲーム開始時は、全Optionをオフ状態にしておく。
foreach(GameObject g in options)
{
g.SetActive(false);
}
}
void Update()
{
playerPos = transform.position;
float h = Mathf.Abs(Input.GetAxis("Horizontal"));
float v = Mathf.Abs(Input.GetAxis("Vertical"));
if (h > 0.5f || v > 0.5f)
{
moveOK = true;
}
else
{
moveOK = false;
}
if(moveOK)
{
playerPosRecord.Insert(0, playerPos);
playerPosRecord.RemoveAt(playerPosRecord.Count - 1);
}
options[0].transform.position = playerPosRecord[9];
options[1].transform.position = playerPosRecord[19];
options[2].transform.position = playerPosRecord[29];
options[3].transform.position = playerPosRecord[39];
}
// ★追加
public void AddOptionCount()
{
optionCount += 1;
// optionCountの数字によって、各Optionをオンにする。
switch (optionCount)
{
case 1:
options[0].SetActive(true);
break;
case 2:
options[1].SetActive(true);
break;
case 3:
options[2].SetActive(true);
break;
case 4:
options[3].SetActive(true);
break;
}
}
}
オプションアイテム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OptionItem : ItemBase
{
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ItemGet();
other.GetComponent<OptionController>().AddOptionCount();
}
}
}
【2021版】Danmaku(基礎/全55回)
他のコースを見るOptionのオン・オフの管理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OptionController : MonoBehaviour
{
public GameObject[] options;
private bool moveOK = false;
private Vector3 playerPos;
private List<Vector3> playerPosRecord = new List<Vector3>();
// ★追加
private int optionCount = 0;
void Start()
{
playerPos = transform.position;
for (int i = 0; i < 40; i++)
{
playerPosRecord.Add(playerPos);
}
// ★追加
// ゲーム開始時は、全Optionをオフ状態にしておく。
foreach(GameObject g in options)
{
g.SetActive(false);
}
}
void Update()
{
playerPos = transform.position;
float h = Mathf.Abs(Input.GetAxis("Horizontal"));
float v = Mathf.Abs(Input.GetAxis("Vertical"));
if (h > 0.5f || v > 0.5f)
{
moveOK = true;
}
else
{
moveOK = false;
}
if(moveOK)
{
playerPosRecord.Insert(0, playerPos);
playerPosRecord.RemoveAt(playerPosRecord.Count - 1);
}
options[0].transform.position = playerPosRecord[9];
options[1].transform.position = playerPosRecord[19];
options[2].transform.position = playerPosRecord[29];
options[3].transform.position = playerPosRecord[39];
}
// ★追加
public void AddOptionCount()
{
optionCount += 1;
// optionCountの数字によって、各Optionをオンにする。
switch (optionCount)
{
case 1:
options[0].SetActive(true);
break;
case 2:
options[1].SetActive(true);
break;
case 3:
options[2].SetActive(true);
break;
case 4:
options[3].SetActive(true);
break;
}
}
}
オプションアイテム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OptionItem : ItemBase
{
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ItemGet();
other.GetComponent<OptionController>().AddOptionCount();
}
}
}
攻撃力の強化③(オプションアイテム)