私はUnityでRPGゲームをC#でやっていますが、特定の数の敵を殺すクエストシステムを実行すると、シーンに3人の敵を持っていて、クエストの対象になっている:3人の敵を殺す。クエストをアクティブにして後でアクティブにする前にそれらを殺すと、報酬(この場合は経験)が得られません。どのように私は敵を告げることができ、クエストが私にすでに必要な敵を殺してクエストを受けることが検出された場合、それと同等の報酬を私に与えることができますか?シーン内の「kill」イベントの認識を達成する方法
は、ここでは、2つの必要なスクリプトは、私は思う:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestObject : MonoBehaviour {
public int questNumber;
public QuestManager qManager;
public string startText;
public string endText;
public bool isItemQuest;
public string targetItem;
public bool isEnemyQuest;
public string targetEnemy;
public int enemiesToKill;
private int enemyKillCount;
private PlayerStats playerStats;
public int EXPToGive;
void Start() {
playerStats = FindObjectOfType <PlayerStats>();
}
void Update() {
if (isItemQuest) {
if (qManager.itemCollected == targetItem) {
qManager.itemCollected = null;
EndQuest();
}
}
if (isEnemyQuest) {
if (qManager.enemyKilled == targetEnemy) {
qManager.enemyKilled = null;
enemyKillCount++;
}
if (enemyKillCount >= enemiesToKill) {
EndQuest();
}
}
}
public void StartQuest(){
qManager.ShowQuestText (startText);
}
public void EndQuest(){
qManager.ShowQuestText (endText);
playerStats.AddEXP (EXPToGive);
qManager.questCompleted [questNumber] = true;
gameObject.SetActive (false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHealth : MonoBehaviour {
public int startingHealth;
public int currentHealth;
public GameObject damageBurst;
private PlayerStats playerStats;
public int EXPToGive;
public string enemyQuestName;
private QuestManager qManager;
void Start()
{
// Setting up the references.
//anim = GetComponent <Animator>();
//enemyAudio = GetComponent <AudioSource>();
//enemyMovement = GetComponent <EnemyMovement>();
//enemyAttacking = GetComponentInChildren <EnemyAttack>();
// Set the initial health of the player.
currentHealth = startingHealth;
playerStats = FindObjectOfType <PlayerStats>();
qManager = FindObjectOfType <QuestManager>();
}
void Update()
{
if (currentHealth <= 0) {
qManager.enemyKilled = enemyQuestName;
Destroy (gameObject);
playerStats.AddEXP (EXPToGive);
}
}
public void TakeDamage (int amountDamage)
{
// Reduce the current health by the damage amount.
currentHealth -= amountDamage;
Instantiate (damageBurst, transform.position, transform.rotation);
}
public void SetMaxHelth() {
currentHealth = startingHealth;
}
}
ありがとうございますが、私はAddKill(this)がこの情報をどこに送信しているのか分からず、AddKillを置く場所があります。そしてGetKillCount()?そして私は敵のカウンターを行う方法を知らない私を助けることができますか?私は2つのタイプの敵であるゴブリンとスライムを持っています。 – adrinator8