如何修复 } Unity C# 中的预期错误?
How can I fix } expected error in Unity C#?
我的 C# 代码有点问题,所以我这里有这个简单的 PlayerHealth 代码,Unity 总是给我这个错误:Unity Bracket Error
代码:
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);
}
}
}
}
感谢您的帮助! :D
检查你的OnCollisionEnter函数,参数有误
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);
}
}
}
}
我的 C# 代码有点问题,所以我这里有这个简单的 PlayerHealth 代码,Unity 总是给我这个错误:Unity Bracket Error
代码:
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);
}
}
}
}
感谢您的帮助! :D
检查你的OnCollisionEnter函数,参数有误
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);
}
}
}
}