I have this code that has been posted on here quite a few times and changed as I go along with it. What I need now is to use this same code in a different scene, only I want it to load a different level than what it has on it now.
If anyone could help me with that it would be great.
Here is the code once again:
using UnityEngine;
using System.Collections;
public class DamagableObject : MonoBehaviour
{
public bool m_Invincible = false;
public float m_MaxHealth = 100f;
public string WinScreen;
[SerializeField]
public float m_Health = 100f;
GUISkin scoreSkin;
public DecayingObject m_DeathEffectPrefab;
public DecayingObject m_RemainsPrefab;
public string m_DeathAnimation;
/*public virtual float health
{
set
{
if (!m_Invincible || m_Health < value)
{
m_Health = value;
}
if (m_Health <= 0)
{
Death();
}
else if (m_Health > m_MaxHealth)
{
m_Health = m_MaxHealth;
}
}
get
{
return m_Health;
}
}*/
public virtual void DealDamage(float val, Vector3 pos, Vector3 normal)
{
if (val > 0f && !m_Invincible)
{
m_Health -= val;
if (m_Health <= 0)
{
Death();
}
}
}
public virtual void Heal(float val)
{
if (val > 0f)
{
m_Health += val;
if (m_Health > m_MaxHealth)
{
m_Health = m_MaxHealth;
}
}
}
public float GetHealth()
{
return m_Health;
}
protected void Start() {
bool error = false;
if (m_MaxHealth <= 0)
{
Debug.LogError("Max health can't be less than or equal to 0");
error = true;
}
if (m_Health > m_MaxHealth || m_Health <= 0)
{
Debug.LogError("Invalid health range expected 0-" + m_MaxHealth + " got " + m_Health);
error = true;
}
if (error)
{
Debug.Break();
}
}
public void Death()
{
if (m_DeathEffectPrefab != null)
{
Instantiate(m_DeathEffectPrefab, transform.position, transform.rotation);
}
if (animation != null && animation[m_DeathAnimation] != null)
{
animation.CrossFade(m_DeathAnimation, 0.5f, PlayMode.StopAll);
if (m_RemainsPrefab != null)
{
StartCoroutine("WaitForDeathAnimation", animation[m_DeathAnimation].length);
}
}
else
{
LogicalEvent(m_RemainsPrefab);
//if (m_RemainsPrefab != null)
//{
// Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
//}
//Scoring.m_score = 5;
//Destroy(gameObject);
}
}
void LogicalEvent(DecayingObject m_RemainsPrefab)
{
if (m_RemainsPrefab != null)
{
Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
}
Destroy(gameObject);
Scoring.m_score += 10;
}
protected IEnumerator WaitForDeathAnimation(float time)
{
yield return new WaitForSeconds(time);
Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
Destroy(gameObject);
}
//public Texture2D background = null;
//public Texture2D healthbar = null;
void OnGUI()
{
//Draw Background
//GUI.skin = scoreSkin;
GUI.color = Color.red;
GUI.Box(new Rect(55,5,100,20),Scoring.m_score.ToString());
if(Scoring.m_score == 180)
{
Application.LoadLevel("LeftLung");
}
//GUI.DrawTexture(new Rect(25.0f,25.0f,120.0f,14.0f),background);
//GUI.color = Color.red;
//Draw Healthbar
//GUI.BeginGroup(new Rect(30.0f,30.0f,115.0f *(m_MaxHealth / m_Health),10.0f));
//GUI.color =Color.red;
//GUI.DrawTexture(new Rect(0.5f,0.10f,120.0f,10.0f),healthbar);
//GUI.EndGroup();
}
void Update(DecayingObject m_RemainsPrefab)
{
LogicalEvent(m_RemainsPrefab);
Scoring.m_score ++;
}
}