小编Tie*_*ung的帖子

在 Unity 中退出 Playmode 后返回 ScriptableObject 的原始值

我有一个像这样的 ScriptableObject

在此输入图像描述

在 Playmode 期间我调整 CurrenHealthValue

在此输入图像描述

当我存在 Playmode 时,CurrentHealthValue=80 不会返回到 40,我知道这是 ScriptableObject 的工作原理,但我想知道是否有任何方法可以在存在 Playmode 后自动返回 40 原始值,而不是手动返回在开始新的 Playmode 之前将值重写为 40。

unity-game-engine scriptable-object

2
推荐指数
1
解决办法
1188
查看次数

UnityException:不允许从 MonoBehaviour 构造函数调用 get_time

我正在尝试制定一种方法来防止玩家发送垃圾邮件空格键。

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

public class PlayerControllerX : MonoBehaviour
{
    public GameObject dogPrefab;
    private float setTime = 2.0f;
    private float timer = Time.time;

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= setTime)
        {
            SpawnDog();
        }
    }
    void SpawnDog()
    {
        // On spacebar press, send dog
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(dogPrefab, transform.position, dogPrefab.transform.rotation);
            timer = 0;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

这是来自 Unity 的错误声明:我认为这不是逻辑错误

UnityExceptionget_time不允许从 MonoBehaviour 构造函数(或实例字段初始值设定项)调用,而是在 …

c# unity-game-engine

1
推荐指数
1
解决办法
1449
查看次数

标签 统计

unity-game-engine ×2

c# ×1

scriptable-object ×1