我有一个像这样的 ScriptableObject
在 Playmode 期间我调整 CurrenHealthValue
当我存在 Playmode 时,CurrentHealthValue=80 不会返回到 40,我知道这是 ScriptableObject 的工作原理,但我想知道是否有任何方法可以在存在 Playmode 后自动返回 40 原始值,而不是手动返回在开始新的 Playmode 之前将值重写为 40。
我正在尝试制定一种方法来防止玩家发送垃圾邮件空格键。
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 的错误声明:我认为这不是逻辑错误
UnityException
:get_time
不允许从 MonoBehaviour 构造函数(或实例字段初始值设定项)调用,而是在 …