为什么不下一级加载?

时间:2017-03-12 18:41:19

标签: c# unity5

我有两个脚本。一个附加到主GameObject名为player(实际玩家)和一个处理附加到空GameObject的场景加载。 所以......问题集中在CompleteLevel()方法和OnTriggerEnter()方法上。我提到我在目标游戏对象上放了一个“目标”标签。当我与目标GameObject碰撞时没有任何反应。我有两个当我与Goal GameObject发生碰撞时,我希望加载下一个。在Build设置中加载了leavels。我不知道我错过了什么,为什么剧本不起作用...... 请帮忙。如果你有解决方案,请记下来。谢谢。 以下是脚本: 附加到“玩家”GameObject的那个:

 public class PlayerMouvement : MonoBehaviour {
 public float moveSpeed ; 
 public Vector3 spawn;
 public GameObject deathParticles;
 public float fallDistance;
 private Vector3 input;
 private Rigidbody rb;
 private float maxSpeed = 5;


 // Use this for initialization
 void Start () 
 {
     rb = GetComponent<Rigidbody> ();
     spawn = transform.position;
 }

 // Update is called once per frame
 void Update () 
 {

     //Takes mouvment input from the player keys.
     input = new Vector3 (Input.GetAxisRaw ("Vertical"), 0, Input.GetAxisRaw ("Horizontal"));
     //This ensurs that the acceleration wil be snappy,and dramatic,not progresive.
     if (rb.velocity.magnitude < maxSpeed) 
     {
         rb.velocity = new Vector3 (Input.GetAxisRaw ("Vertical"), 0, Input.GetAxisRaw ("Horizontal")) * maxSpeed;
     }
     //This makes shore that the player will mouve based on input.
     //print (input);
     rb.AddForce (input * moveSpeed);  
     //if the player falls of the map the Death() function will be called.
     if (transform.position.y < fallDistance) 
     {
         Death ();
     }
 }
 //If the player hits an enamy the Death() function is called.
 void OnCollisionEnter(Collision other){
     if (other.transform.tag == "Enamy") 
     {
         Death ();
     }
 }
 //Loads the next Level when the player collides with the "Goal".
 void OnTriggerEnter(Collider other)
 {
     if (other.transform.tag == "Goal") 
     {
         GameManager.CompleteLevel();
     }
 }

 //This makes the player die,playe death particles and respown at the  starting point.
 void Death()
 {
     print ("The player has died");
     Instantiate (deathParticles,transform.position, Quaternion.identity);
     transform.position = spawn;
 }
}

我将这个名为GameManager的游戏附加到空GameObject:

enter code here

 using System.Collections.Generic; 
 using System.Collections;
 using UnityEngine; 
 using UnityEngine.SceneManagement;


 public class GameManager : MonoBehaviour {
 public static int currentScore;
 public static int highScore;
 public static int currentLevel = 0;
 public static int unlockedLevel;

 public static void CompleteLevel()
 {
     currentLevel +=1;
     SceneManager.LoadScene (currentLevel +1);
 }

0 个答案:

没有答案