★敵をデザインする
![70388184 efaf 4c52 8422 be9bcaa77ba1](https://codegenius.org/uploads/slide/image/7307/70388184-efaf-4c52-8422-be9bcaa77ba1.jpeg)
![Fce5b036 a41c 43d2 b141 8116f0bbe036](https://codegenius.org/uploads/slide/image/7308/fce5b036-a41c-43d2-b141-8116f0bbe036.jpeg)
![E2c17c68 6343 4488 8131 2e1df3994b40](https://codegenius.org/uploads/slide/image/7309/e2c17c68-6343-4488-8131-2e1df3994b40.jpeg)
敵を破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHP : MonoBehaviour
{
public GameObject effectPrefab;
public int scoreValue;
private ScoreManager sm;
void Start()
{
sm = GameObject.Find("ScoreLabel").GetComponent<ScoreManager>();
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Shell"))
{
Destroy(other.gameObject);
Destroy(gameObject);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 1.5f);
sm.AddScore(scoreValue);
}
}
}
![70388184 efaf 4c52 8422 be9bcaa77ba1](https://codegenius.org/uploads/slide/image/7307/70388184-efaf-4c52-8422-be9bcaa77ba1.jpeg)
![Fce5b036 a41c 43d2 b141 8116f0bbe036](https://codegenius.org/uploads/slide/image/7308/fce5b036-a41c-43d2-b141-8116f0bbe036.jpeg)
![E2c17c68 6343 4488 8131 2e1df3994b40](https://codegenius.org/uploads/slide/image/7309/e2c17c68-6343-4488-8131-2e1df3994b40.jpeg)
敵を破壊する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHP : MonoBehaviour
{
public GameObject effectPrefab;
public int scoreValue;
private ScoreManager sm;
void Start()
{
sm = GameObject.Find("ScoreLabel").GetComponent<ScoreManager>();
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Shell"))
{
Destroy(other.gameObject);
Destroy(gameObject);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 1.5f);
sm.AddScore(scoreValue);
}
}
}
★敵をデザインする