01-09-2020, Saat: 09:33
Arkadaşlar 2d bir oyun üzerine çalışıyorum bir düşman var ve bu düşmanı karakter öldürünce 5 saniye sonra yeniden doğması gerek
ancak şu hatayla karşılaşıyorum "ArgumentException: The Object you want to instantiate is null."
Komutlarım şu şekilde;
Hata satırı ise şu;
Lütfen yardım edin günlerdir çözemedim
ancak şu hatayla karşılaşıyorum "ArgumentException: The Object you want to instantiate is null."
Komutlarım şu şekilde;
Kod:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public enum EnemyState
{
idle,
walk,
attack,
stagger
}
public class Enemy : MonoBehaviour
{
public GameObject FloatingTextPrefab;
public EnemyState currentState;
public FloatValue maxHealth;
public float health;
public string enemyName;
public int baseAttack;
public float moveSpeed;
public Image healthBar;
public float initHealth;
private UnityEngine.Object enemyRef;
void Start()
{
enemyRef = Resources.Load("wolf.prefab") as GameObject;
initHealth = health;
}
// Update is called once per frame
void Update()
{
healthBar.fillAmount = health / initHealth;
}
private void Awake()
{
health = maxHealth.initialValue;
}
private void TakeDamage(float damage)
{
if (FloatingTextPrefab)
{
ShowFloatingText();
}
health --;
if(health <= 0)
{
this.gameObject.SetActive(false);
Invoke("Respawn", 5);
}
}
void Respawn()
{
GameObject enemyClone = (GameObject)Instantiate(enemyRef);
enemyClone.transform.position = transform.position;
Destroy(gameObject);
}
void ShowFloatingText()
{
var go = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
go.GetComponent<TextMeshPro>().text = health.ToString();
}
public void Knock(Rigidbody2D myRigidbody, float knockTime, float damage)
{
StartCoroutine(KnockCo(myRigidbody, knockTime));
TakeDamage(damage);
}
private IEnumerator KnockCo(Rigidbody2D myRigidbody, float knockTime)
{
if (myRigidbody != null)
{
yield return new WaitForSeconds(knockTime);
myRigidbody.velocity = Vector2.zero;
currentState = EnemyState.idle;
myRigidbody.velocity = Vector2.zero;
}
}
}
Hata satırı ise şu;
Kod:
GameObject enemyClone = (GameObject)Instantiate(enemyRef);
Lütfen yardım edin günlerdir çözemedim
