gpt4 book ai didi

How do I stop animations in a list from cancelling out one another in unity?(如何阻止列表中的动画相互抵消?)

翻译 作者:bug小助手 更新时间:2023-10-26 22:24:57 25 4
gpt4 key购买 nike



I have some animations that are on spikes. The idea is they will fall on my Player's head and kill the player. The problem is, I have many of them in a row. I have put all those animations in a list and they all have the same script. I am using player prefs to communicate between scripts and the animations keep cancelling out one another. When I go on the gameobject, (on the ground and has a script that detects the player) The animation will play and kill the player. The problem is that when I go onto the next gameobject, the first anim is running and it just stops.

我有一些动画是在钉子上。他们的想法是,他们会落在我的球员的头上,杀死球员。问题是,我有很多这样的人。我把所有这些动画放在一个列表中,它们都有相同的剧本。我正在使用播放器首选项来在脚本和动画之间进行交流,并且动画之间不断地相互抵消。当我在游戏对象上(在地面上,有一个检测玩家的脚本)时,动画将播放并杀死玩家。问题是,当我转到下一个游戏对象时,第一个动画正在运行,然后它就停止了。


Here is my script that plays the anim:

以下是我播放动画的剧本:


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

public class pref_fall_spike : MonoBehaviour
{
//public Animation anim;
int get_spike = 0;
public Animation anim;
int get_spike_1 = 0;
bool stop_anim = false;
void Start()
{
//anim = GetComponent<Animation>();
}

public void AlertObservers(string message)
{
if (message.Equals("spike_animation_ended"))
{

stop_anim = true;
}

}
void Update()
{
//anim.Play("real_spike_fall");
if (PlayerPrefs.GetInt("spike_fall") == 1)
{

anim.Play("real_spike_fall");

}
if (PlayerPrefs.GetInt("spike_fall_1") == 1)
{
anim.Play("real_spike_fall_2");
}
//get_spike = PlayerPrefs.GetInt("spike_fall");
if (stop_anim == true)
{
PlayerPrefs.SetInt("spike_fall", 0);
stop_anim = false;
anim.Stop();
}
//if (get_spike == 1)
//{

//anim.Play();
//}
}
}

It seems to work when I stop the anim.Play() for the second animation, but the second animation also will not play...

当我停止动画时,它似乎起作用了。Play()用于第二个动画,但第二个动画也不会播放...


Is there a way to fix this?

有什么办法可以解决这个问题吗?


更多回答
优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com