I really tried hard to figure it out on my own before asking this question but no success.
I want to load new level after my int variable increases certain amount.
It worked with two levels but because of new scene (Level) load everything gets destroyed.
I made new empty object with my Script attached to it and DontDestroyOnLoad which should do the trick but now I have different problem with The name `enemy’ does not exist in the current context
I have my variable attached to
enemy Script:
public int Hits = 1;
Then my increasement at Projectile script:
void OnTriggerEnter(Collider otherObject)
{
if (otherObject .tag == "enemy")
{
Enemy enemy = (Enemy)otherObject.gameObject.GetComponent("Enemy");
enemy.Hits += 1;
}
}
And lastly my empty object NewLevel has its own script:
using UnityEngine;
using System.Collections;
public class NewLevel : MonoBehaviour
{
void Update ()
{
Enemy enemy = (Enemy)otherObject.gameObject.GetComponent("Enemy");
if (enemy.Hits == 2) Application.LoadLevel (4);
else if (enemy.Hits == 3) Application.LoadLevel (5);
else if (enemy.Hits == 4) Application.LoadLevel (6);
}
}
I understand that my error is somewhere at NewLevel but I can’t figure it out.
I also tried switch instead of if statements.
Thank you for any advice.