- Home /
This question was
closed Sep 02, 2019 at 03:11 PM by
noobgamemake.
Question by
noobgamemake · May 11, 2019 at 08:19 PM ·
codepage
What wrong with this code.The value of hp didt change when it touch the "LaserBeam" obj
public class bosshp : MonoBehaviour {
[Header("hp")]
public float hp = 3;
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "LaserBeam")
{
hp = hp - 1;
}
}
void Update()
{
if (hp <= 0)
{
Destroy(gameObject);
}
Debug.Log("idk" + hp);
}
}
Comment
Best Answer
Answer by Karakuik · May 11, 2019 at 09:17 PM
Troubleshoot it.
Add a Debug.Log("Hit!") either above or below the hp=hp-1. If that doesn't work make sure your collisions are properly set up. i.e: Make sure the laser has a collider on it and that you have a collider.
Answer by noobgamemake · Sep 02, 2019 at 01:33 PM
I add the normal collider but not 2Dcollider so it dont work Thank you