Hi all. I'm trying to progress from one scene to the next. Only problem is I keep getting the error. The next level collision is a capsule collider, I have got interaction with player and capsule because I've got it set up for the capsule to disappear when they collide. This interaction can be turned on or off with out any problems (true/false thing) Any help, thoughts insight? greatly appreciated.
Open up the scene you try to transition to in the editor, then press File>Build Settings and in the window for scenes press "Add Current" ( or whatever it says, can't quite recall. ) The error is simply that Unity can't find the scene you try to open since it's not in the list of available scenes.
Hi Kona, I have done this, and it sort of works... before it didn't work, then I added a string to my nextLevel script and it goes to the next level, but it does this instantly now :/ any thoughts on how to get so it only when collision? My Code: Code (CSharp): using UnityEngine; using System.Collections; public class NewLevel : MonoBehaviour { public PlayerController controller; public string Level_2; // Use this for initialization void Start() { controller = (PlayerController)transform.GetComponent("PlayerController"); } void Update() { Application.LoadLevel(Level_2); } } It will only go to next level if (Level_2) is in the string field. If its not, it just comes up with error.
Well that script occurs on 'Update'. It'll happen the first time it updates. Instead wait for something event. For example if that script was on a GameObject with a BoxCollider attached flagged as a trigger. You could listen for the 'OnTriggerEnter', and test if the collider who entered is the player, and then load if true.
I have a onTrigger event on my PlayerControlller script. and the capsule collider is tagged as 'istrigger' Would the trigger need to be moved? This is my playerController script. Code (CSharp): using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; private Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * speed); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Rock")) { other.gameObject.SetActive(true); } if (other.gameObject.CompareTag("End")) { other.gameObject.SetActive(true); } } }
Don't use the player collider as a trigger, instead make the object that should trigger a level change to a trigger, and try Code (CSharp): public void OnTriggerEnter( Collider other ) { if( other.CompareTag( "Player" )) { ChangeScene(); } } public void ChangeScene() { Application.LoadLevel( "levelName" ); } Also do note that game objects that are disabled will not be able to call triggers, since all components in its hierarchy are also disabled, that includes their colliders.