I am trying to say, when the player enters the trigger, the player can press C to go to the next level. Please help
C#
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
public class LevelChange : MonoBehaviour {
public string loadLevel;
void OnTriggerEnter(Collider other) {
Time.timeScale = 0;
if(Input.GetKey(KeyCode.C)){
Application.LoadLevel (loadLevel);
Debug.Log("Level loaded: " + loadLevel);
}
}
}
Maui-M
3
Try using OnTriggerStay instead of OnTriggerEnter
Also note: Trigger events are only sent if one of the colliders also has a rigidbody attached.
Input should be called in Update Loop :
http://docs.unity3d.com/ScriptReference/Input.html
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
public class LevelChange: MonoBehaviour {
public string loadLevel;
bool CanLoad = false;
void OnTriggerEnter(Collider other) {
if(other.CompareTag("Player")){
CanLoad = true;
}
}
void Update(){
if(CanLoad){
Time.timeScale = 0;
if(Input.GetKeyDown(KeyCode.C)){
Application.LoadLevel (loadLevel);
Debug.Log("Level loaded: " + loadLevel);
}
}
}
}