Assets\Scripts\Bullet.cs(33,56): error CS1061: 'Enemy' does not contain a definition for 'ChangeHealth' and no accessible extension method 'ChangeHealth' accepting a first argument of type 'Enemy' could be found (are you missing a using directive or an assembly reference? ошибка
код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour {
public float speed;
public float lifeTime;
public float distance;
public int damage;
public LayerMask whatIsSolid;
[SerializeField] bool enemyBullet;
public GameObject destroyEffect;
private void Start()
{
Invoke("DestroyBullet", lifeTime);
}
private void Update()
{
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, distance, whatIsSolid);
if (hitInfo.collider != null)
{
if (hitInfo.collider.CompareTag("Enemy"))
{
hitInfo.collider.GetComponent<Enemy>().TakeDamage(damage);
}
if (hitInfo.collider.CompareTag("Player") && enemyBullet)
{
hitInfo.collider.GetComponent<Enemy>().ChangeHealth(-damage);
}
DestroyBullet();
}
transform.Translate(Vector2.up * speed * Time.deltaTime);
}
void DestroyBullet() {
Instantiate(destroyEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}