#some dumb error is happening and i cant seem to fix it
1 messages · Page 1 of 1 (latest)
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);
}
}
make sure you spelled it right
i did
show the EnemyBehaviour class then
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);
}
}
}
Also go to #854851968446365696 for how to paste code
wdym
Takehit != TakeHit
Use a site like https://gdl.space/ to paste the code in next time, then send the link here