如何在Unity的Karting Microgame中重复使用电源UPS?
我正在修改Unity的卡丁车微型游戏,我想使速度垫能够多次使用一次,因为它们的编程方式可以使其能够使用,以便它们只能用完,直到达到Maxtime“ x”秒数。播放器甚至可以在达到Maxtime之后拿起电力,但没有任何作用... 我强烈建议您下载卡丁车微型,以更好地了解问题,但这是电源的代码:
using KartGame.KartSystems;
using UnityEngine;
using UnityEngine.Events;
public class ArcadeKartPowerup : MonoBehaviour {
public ArcadeKart.StatPowerup boostStats = new ArcadeKart.StatPowerup
{
MaxTime = 5f
};
public bool isCoolingDown { get; private set; }
public float lastActivatedTimestamp { get; private set; }
public float cooldown = 5f;
public bool disableGameObjectWhenActivated;
public UnityEvent onPowerupActivated;
public UnityEvent onPowerupFinishCooldown;
private void Awake()
{
lastActivatedTimestamp = -9999f;
}
private void Update()
{
if (isCoolingDown)
{
if (Time.time - lastActivatedTimestamp > cooldown)
{
//finished cooldown!
isCoolingDown = false;
onPowerupFinishCooldown.Invoke();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (isCoolingDown) return;
var rb = other.attachedRigidbody;
if (rb) {
var kart = rb.GetComponent<ArcadeKart>();
if (kart)
{
lastActivatedTimestamp = Time.time;
kart.AddPowerup(this.boostStats);
onPowerupActivated.Invoke();
isCoolingDown = true;
if (disableGameObjectWhenActivated) this.gameObject.SetActive(false);
}
}
}
}
我没有设法将卡丁车代码放置在此处,因为它超出了字符限制,但是您可以通过在Unity Hub中下载Karting Microgame轻松检查一下!在这种情况下,卡丁车的脚本起到了可以提高统计数据的功能。 我有(或不使用)工作的想法是做到这一点,以便每次“ iScollingdown”返回时,只需添加另一个可控制效果持续到Maxtime变量的变量,例如“ Maxtime = Maxtime = Maxtime + formationDuration。 “但是我不知道该如何实施... 很抱歉,如果这个问题有一个非常明显的答案,但是我真的不了解脚本!
I'm modifying unity's karting microgame and I wanted to make the speed-pads able to be used more than once because the way they are programmed makes it so that they can only be used up until the MaxTime "x" amount of seconds is reached. The player can even pick up the power-up after the MaxTime is reached but it doesn't do anything...
I strongly suggest you download the karting microgame to have a better view of the issue but here is the code for the power-up:
using KartGame.KartSystems;
using UnityEngine;
using UnityEngine.Events;
public class ArcadeKartPowerup : MonoBehaviour {
public ArcadeKart.StatPowerup boostStats = new ArcadeKart.StatPowerup
{
MaxTime = 5f
};
public bool isCoolingDown { get; private set; }
public float lastActivatedTimestamp { get; private set; }
public float cooldown = 5f;
public bool disableGameObjectWhenActivated;
public UnityEvent onPowerupActivated;
public UnityEvent onPowerupFinishCooldown;
private void Awake()
{
lastActivatedTimestamp = -9999f;
}
private void Update()
{
if (isCoolingDown)
{
if (Time.time - lastActivatedTimestamp > cooldown)
{
//finished cooldown!
isCoolingDown = false;
onPowerupFinishCooldown.Invoke();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (isCoolingDown) return;
var rb = other.attachedRigidbody;
if (rb) {
var kart = rb.GetComponent<ArcadeKart>();
if (kart)
{
lastActivatedTimestamp = Time.time;
kart.AddPowerup(this.boostStats);
onPowerupActivated.Invoke();
isCoolingDown = true;
if (disableGameObjectWhenActivated) this.gameObject.SetActive(false);
}
}
}
}
I'm did not manage to place the kart code here because it goes over the character limit, but you can easily check it out by downloading the karting microgame in Unity Hub! In this context, the Kart's script serves the function of provinding the stats that can be boosted.
The idea that I had that might (or not) work is to make it so that every time the "isCollingDown" returns just add another variable that controls how long the effect lasts to the MaxTime variable, something like "MaxTime = MaxTime + EffectDuration." But I don't know how to implement this...
I'm sorry if there is a very obvious answer to this issue but I really don't understand a lot about scripts!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,它已经具有您想要成就的功能,因此您不必编码任何内容。
您会看到属性
disablegameObjectWhenactivated
。现在应该将此设置为真。只需将其设置为false即可,它将具有冷却时间,而不是随后禁用蜜蜂。现在,如果您想摆脱冷却时间,我只会将冷却时间设置为0。It actually already has a function build in for what you want to achive so you do not have to code anything.
You see the property
disableGameObjectWhenActivated
. This one should be set true right now. Just set it false and it will have a cooldown instead of beeing disabled afterwards. Now if you want to get rid of the cooldown I would just set the cooldown to 0.