Ahmet Efe11
Decapat
- Katılım
- 18 Ağustos 2023
- Mesajlar
- 158
- Çözümler
- 1
Daha fazla
- Cinsiyet
- Erkek
Kod:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class characterhealth : MonoBehaviour
{
// health
public int Maxhealth = 100;
public int currenthealth;
public Healthbar healtbar;
//Enemy AttackTime
public bool enemyattack;
public float enemytimer;
void Start()
{
currenthealth = Maxhealth;
enemytimer = 1.5f;
}
// düşmanın vurma arlığı
void EnemyAttackTimer()
{
if (enemyattack == false)
{
enemytimer -= Time.deltaTime;
}
if (enemytimer < 0)
{
enemytimer = 0f;
}
if (enemytimer == 0f)
{
enemyattack = true;
enemytimer = 1.5f;
}
}
// düşmana vurduğumuzda kitlenmesi
public void characterdamage()
{
if (Input.GetKeyDown(KeyCode.E))
{
enemyattack = false;
}
}
//karakterin hasar alması
public void Takedamage(int damage)
{
if (enemyattack == true)
{
currenthealth -= 20;
enemyattack = false;
}
healtbar.SetHealth(currenthealth);
}
// Update is called once per frame
void Update()
{
EnemyAttackTimer();
characterdamage();
if (Input.GetKeyDown(KeyCode.Z))
{
enemyattack = true;
Takedamage(20);
}
}
}
Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Healthbar : MonoBehaviour
{
public Slider slider;
public void SetMaxHealth(int health)
{
slider.maxValue = health;
slider.value = health;
}
public void SetHealth(int health)
{
slider.value = health;
}
}
hata olarakta bunu alıyorum .
NullReferenceException: Object reference not set to an instance of an object
characterhealth.Takedamage (System.Int32 damage) (at Assets/script/characterhealth.cs:62)
characterhealth.Update () (at Assets/script/characterhealth.cs:75)
Son düzenleyen: Moderatör: