gpt4 book ai didi

Unity C#. Code is executing with delay (I guess?)(Unity C#.代码正在延迟执行(我猜?))

转载 作者:bug小助手 更新时间:2023-10-25 16:01:24 31 4
gpt4 key购买 nike



So, the i want to make a particles when the player is walking. But there's a problem:
My player moves - there is no particle code executing, BUT when he's stops - the particles are appear and after some period of time, they're destroying with the duration i set in Unity's Inspector.
BUT! When i start moving the player during the particles appear duration, they're no longer destroying themselves untill the player stops.
Code for particles:

所以,当玩家行走时,我想做一个粒子。但有一个问题:我的玩家移动-没有粒子代码执行,但当他停下来的时候-粒子出现了,一段时间后,他们正在摧毁我在单位的检验者中设置的持续时间。但!当我在粒子出现期间开始移动玩家时,它们不再自我毁灭,直到玩家停止为止。粒子代码:


using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class ParticleOfSteps : MonoBehaviour
{
public ParticleSystem collectParticle;
public Vector3 playerMovement;
//public Vector3 oldRotationPosition;
private GameObject Player;
public float cor = 0.1f;
private void Start()
{
Player = GameObject.Find("Player");
playerMovement = Player.transform.position;
}
void Update()
{
Debug.Log("1");
if (playerMovement != Player.transform.localPosition)
{
Collect();
}


}
private void LateUpdate()
{
}
public void Collect()
{
StartCoroutine(delayForPlayer());
}
public IEnumerator delayForPlayer()
{
playerMovement = Player.transform.localPosition;
yield return new WaitForSeconds(Time.deltaTime);
collectParticle.Play();
Debug.Log("2");
}
}


as you can see, i tried lots of things. Even using LateUpdate for playerMovement = Player.transform.localPosition; (Like it'd help me, yes)
I used WaitForSeconds() func, because i had thought that the problem was in updating coordinates of playerMovement, but it didn't helped me.

如你所见,我尝试了很多方法。即使对playerMotion=Player.Trans.LocalPosition;使用LateUpdate;(就像它对我有帮助一样,是的),我也使用了WaitForSecond()函数,因为我曾认为问题出在更新playerMotion的坐标上,但它对我没有帮助。


Again: i need particles to appear when the player is moving. Please, help!

再说一次:当玩家移动时,我需要粒子出现。求求你,救命!


更多回答

so you put in a delay and then wonder why its delayed?

所以你推迟了,然后想知道为什么要推迟?

Sorry for misunderstanding. I meant not "Delayed" for the exact period of time, it's delayed untill the "W" button(for walking forward), or "S" (For going back) are up. Then the particles appear.

对不起,我误会了。我的意思是不是“延迟”到确切的时间段,而是等到“W”键(用于前进)或“S”(用于后退)被打开时。然后粒子就出现了。

Your question is very unclear. But it sounds like you know what you need you just havent done it yet

你的问题很不清楚。但听起来你知道你需要什么,只是还没有做而已

Can you post the code of the player where he presses W or S and how it influences the particles?

你能贴出玩家按下W或S的代码以及它对粒子的影响吗?

优秀答案推荐
更多回答

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