Assets/health.cs(11,23): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Unexpected symbol `=' in class, struct, or interface member declaration Where have i gone wrong? here's my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class health : MonoBehaviour {
public Slider healthbarslider;
public Text gameOverText;
gameOverText.enabled = false;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "object")
{
healthbarslider.value -= 10f;
}
if (healthbarslider.value == 0)
{
gameOverText.enabled == true;
System.Threading.Thread.Sleep (5000);
Application.LoadLevelAsync(Application.loadedLevelName);
}
}
}
Comment
Best Answer
Answer by DragonTTK · Jun 11, 2017 at 09:24 PM
@c4k3m45t3r These seems to work for me not much was changed compared to your code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Health : MonoBehaviour
{
[Header("References")]
public Slider healthbarslider;
public Text gameOverText;
// Use this for initialization
void Start()
{
gameOverText.enabled = false;
healthbarslider.GetComponent<Slider>();
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "object")
{
healthbarslider.value -= 10f;
}
if (healthbarslider.value <= 0)
{
gameOverText.enabled = true;
//System.Threading.Thread.Sleep(5000);
// Will load level 0 change this to ur level int id u need.
SceneManager.LoadSceneAsync(0);
}
}
}