[英]Unity c# help, doodle jump
I am creating a game similar to doodle jump.我正在创建一个类似于涂鸦跳跃的游戏。
I have programmed my camera to go up after the player but not down, so when the player goes down off camera view he loses.我已经将我的相机编程为在玩家之后上升而不是下降,所以当玩家从摄像机视野中下降时他会失败。
I also want the obstacles that are spawned to be destroyed when they are out of the camera view.我还希望生成的障碍物在镜头视野之外时被摧毁。 I have attached a script to them but it is not working because I am attaching the script to the main object and if it is destroyed then there can't be any more spawning things, so I need to attach the script some how just to the clones, not to the main game object or you may help me write a good script.我已将脚本附加到它们,但它不起作用,因为我将脚本附加到主对象,如果它被破坏,则不能再有任何生成的东西,所以我需要将脚本附加到一些克隆,而不是主要的游戏对象,或者你可以帮我写一个好的脚本。
public GameObject player;
public Camera camera;
public GameObject obstacleclone;
public GameObject platform;
void Start () {
}
void Update () {
if(camera.transform.position.y > obstacleclone.transform.position.y + 10f
|| camera.transform.position.y > platform.transform.position.y + 20f)
{
platform.SetActive(false);
}
}
void OnCollisionEnter(Collision col)
{
StartCoroutine ("go");
}
IEnumerator go()
{
yield return new WaitForSeconds(2f);
Destroy (gameObject);
}
You can use Renderer.OnBecameInvisible It will be called wehn object is no longer visible您可以使用 Renderer.OnBecameInvisible 它将被称为 wehn 对象不再可见
public void OnBecameInvisible()
{
Destroy(gameObject);
}
But your game is endless runner type so use object pooling than creating and destroying objects.It can be simple or complex depending on your needs.但是你的游戏是无尽的跑步者类型,所以使用对象池而不是创建和销毁对象。它可以是简单的,也可以是复杂的,这取决于你的需要。 Also attach camera to your main player so it will follow your player.还将相机连接到您的主播放器,以便它跟随您的播放器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.