- Home /
Quick question. How do i get an object to come down once all AIs are destroyes and then when i come near it it loads a level
Well, The title says it all.
Answer by syclamoth · Sep 28, 2011 at 04:56 PM
Well, you could do something like this-
Put a big trigger volume on the object, and then make a script for counting the number of enemies in the scene-
float heightProportion = 1;
public Vector3 someHighPlace;
public Vector3 someLowPlace;
Update()
{
if(GameObject.FindGameObjectsWithTag ("Enemies").Length == 0)
{
heightProportion = Mathf.Clamp01(heightProportion - Time.deltaTime);
}
transform.position = Vector3.Lerp(someLowPlace, someHighPlace, heightProportion);
}
This will move your object when you run out of things to kill.
Then on your object, do something like this-
OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player")
{
Application.LoadLevel("Next Level");
}
}
This is all strictly psuedocode- while it'll techincally compile in C#, you'll have to adapt it to do exactly what you need it to do. Most notably, you need your enemies to all share a tag, and you need your player to have a different tag.
What do i attach the top one to? Sorry you may have to guide me. In my defense, i am only 11
Both of those snippets go into the same script, but in different places. The top one does the moving, the bottom one does the level changing! Both scripts should be on the same gameObject, and that object should have a large trigger collider on it. You can also have some kind of mesh or particle effect on it, if you want it to look like something, or better still, just put all the visuals on a separate object which is a transform child of the trigger object!