#some dumb error is happening and i cant seem to fix it

1 messages · Page 1 of 1 (latest)

lost owl
#

Assets\ProjectileBehaviour.cs(39,19): error CS1061: 'EnemyBehaviour' does not contain a definition for 'Takehit' and no accessible extension method 'Takehit' accepting a first argument of type 'EnemyBehaviour' could be found (are you missing a using directive or an assembly reference?)

#

public class ProjectileBehaviour : MonoBehaviour
{
public float Speed = 4;
public Vector3 LaunchOffset;
public bool Thrown;

// Start is called before the first frame update
private void Start()
{
    if (Thrown)
    {
        var direction = -transform.right + Vector3.up;
        GetComponent<Rigidbody2D>().AddForce(direction * Speed, ForceMode2D.Impulse);
    }
    transform.Translate(LaunchOffset);

    Destroy(gameObject, 5);
}

// Update is called once per frame
public void Update()
{
    if (!Thrown)
    {
        transform.position += -transform.right * Speed * Time.deltaTime;
    }
    
}

private void OnCollisionEnter2D(Collision2D collision)
{
    var enemy = collision.collider.GetComponent<EnemyBehaviour>();
    if (enemy)
    {
        enemy.Takehit(1);
    }
    Destroy(gameObject);
}

}

lusty stratus
#

make sure you spelled it right

lost owl
#

i did

lusty stratus
#

show the EnemyBehaviour class then

lost owl
#

kk

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBehaviour : MonoBehaviour
{
public float Hitpoints;
public float MaxHitpoints = 5;

// Start is called before the first frame update
void Start()
{
    Hitpoints = MaxHitpoints;
}

public void TakeHit(float damage)
{
    Hitpoints -= damage;
    if(Hitpoints <= 0)
    {
        Destroy(gameObject);
    }
}

}

quick ginkgo
lusty stratus
#

but you also did not spell it right

lost owl
#

wdym

lusty stratus
#

Takehit != TakeHit

quick ginkgo