﻿## 通过场景时停止

除了 Start(Component/GameObject) StartGlobal，ActionKit 还提供了 StartCurrentScene 的启动方式。

StartCurrentScene 会在当前场景切换时会自动停止和回收 Action。

示例代码如下:
```csharp
using UnityEngine;
using UnityEngine.SceneManagement;

namespace QFramework.Example
{
    public class StartCurrentSceneExample : MonoBehaviour
    {
        void Start()
        {
            ActionKit.Sequence()
                .Delay(1.0f)
                .Callback(() =>
                {
                    Debug.Log("printed");
                    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                })
                .Delay(1.0f)
                .Callback(() =>
                {
                    Debug.Log("Not print");
                })
                .StartCurrentScene();
        }
    }
}
```
运行结果如下:
```csharp
// printed
// 间隔 1 秒
// printed
// 间隔 1 秒
// printed
// 间隔 1 秒
// printed
// 间隔 1 秒
// printed
// ...
```

永远不会输出代码中的 Not print，因为当场景变更时，会自动停止动作序列的执行。

好了，这就是 StartCurrentScene 的介绍了。

本文由 QFramework 教程年会员赞助，地址：[https://www.gamepixedu.com/goods/show/55](https://www.gamepixedu.com/goods/show/55)

* QFramework 主页：[qframework.cn](https://qframework.cn)
* QFramework 交流群: 541745166
* QFramework Github 地址: <https://github.com/liangxiegame/qframework>
* QFramework Gitee 地址：<https://gitee.com/liangxiegame/QFramework>