C# 为什么是';下一级负荷是多少?
我有两个脚本。一个附加到名为player(实际玩家)的主游戏对象,另一个处理附加到空游戏对象的场景加载。 所以…问题集中在CompleteLevel()方法和OnTiggerEnter()方法上。我提到我在目标游戏对象上放置了一个“目标”标记。当我与目标游戏对象碰撞时,什么都不会发生。我有两个级别,当我与目标游戏对象碰撞时,我想加载下一个级别。叶子在构建设置中加载。我不知道我错过了什么,为什么脚本不起作用。。。 请帮忙。如果你有解决办法,写下来。谢谢。 以下是脚本: 连接到“玩家”游戏对象的一个:C# 为什么是';下一级负荷是多少?,c#,unity5,C#,Unity5,我有两个脚本。一个附加到名为player(实际玩家)的主游戏对象,另一个处理附加到空游戏对象的场景加载。 所以…问题集中在CompleteLevel()方法和OnTiggerEnter()方法上。我提到我在目标游戏对象上放置了一个“目标”标记。当我与目标游戏对象碰撞时,什么都不会发生。我有两个级别,当我与目标游戏对象碰撞时,我想加载下一个级别。叶子在构建设置中加载。我不知道我错过了什么,为什么脚本不起作用。。。 请帮忙。如果你有解决办法,写下来。谢谢。 以下是脚本: 连接到“玩家”游戏对象的一个
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;
}
}
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);
}
您已经在CompleteLevel方法中增加了currentLevel。您仍然试图在下一行中加载currentLevel+1?这似乎很奇怪,你能告诉我要更改什么吗?我是初学者,我正在学习一些教程,这就是为什么我很容易陷入困境的原因…在CompleteLevel方法中,尝试将第二行更改为SceneManager.LoadScene(currentLevel);