I have a little problem with my C# code, so I have this simple PlayerHealth code here and Unity always gives me this error: Unity Bracket Error
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public float health = 100;
public float damage = 10;
void OnCollisionEnter(otherObj Collision) {
if (otherObj.tag == "Bullet") {
health = health - damage;
if (health < 0)
{
Destroy(gameObject);
}
}
}
}
I appreciate your help! 😀
>Solution :
Check your OnCollisionEnter function, the parameter is wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public float health = 100f;
public float damage = 10f;
void OnCollisionEnter(Collision otherObj)
{
if (otherObj.gameObject.tag == "Bullet")
{
health = health - damage;
if (health < 0)
{
Destroy(gameObject);
}
}
}
}