398
questions
0
votes
1
answer
46
views
Why yield return null can't executed in Start() void
This problem is not always occurred.But when it happened,I can't find a way to fix it.
Here is the code:
void Start()
{
StartCoroutine(test());
}
IEnumerator test()
{
...
0
votes
2
answers
77
views
How to make this IEnumerator generic in a proper way?
Ive got a following coroutine in unity:
IEnumerator DoActionUponReachingRangeCoroutine(Range range, Delegate action, params object[] args)
{
yield return new WaitUntil(() => range....
0
votes
1
answer
46
views
How would I be able to make a Unity GameObject move fluidly using Translate and IEnumerator?
I am making a simple hoops style game where you throw eggs into a moving birds nest. I am trying to get the nest to move between 2 set positions randomly by translating the GameObject for a set period ...
0
votes
1
answer
31
views
Why the timer stop after 1 second
using System.Collections;
using UnityEngine;
public class Timer : MonoBehaviour
{
public ZeitManager zeitmanager;
public IEnumerator TimerDownSekunden()
{
if (zeitmanager....
0
votes
1
answer
52
views
Spawning object when tag is sliced Unity C#
private IEnumerator Spawn()
{
yield return new WaitForSeconds(2f);
while (fruitsSpawned != numberOfFruits)
{
GameObject prefab = fruitPrefabs[Random.Range(0, fruitPrefabs.Length)];...
0
votes
1
answer
46
views
Can't figure out how to start a saved Coroutine variable
My AI units have a few coroutines for different tasks, I wanted to be able to store the last used coroutine so that they can "pause" and "continue", but ran into a trouble that I ...
3
votes
1
answer
226
views
In C#, my IEnumerator is reset / created anew when entering a method / local function. Why? [duplicate]
Consider this example:
List<int> l = [1, 2, 3, 4, 5];
void DoSomethingWith(IEnumerator<int> e) {
Console.WriteLine(e.MoveNext());
Console.WriteLine(e.Current);
}
using(var e = l....
0
votes
2
answers
129
views
Are there a C# equivalents of Python's iter() and next() functions?
Python's iter(.) and next(.) built-in functions allow iterating a list (or other objects that implement __iter__(self) and __next__(self)) without a for loop and without an index.
Does C# have ...
1
vote
1
answer
51
views
Why won't my coroutine run more than once?
In my game, the power ups that the player can pick up, first check to see if the character is already powered up. If not, then it starts the coroutine called "FireBreathing" which handles ...
1
vote
1
answer
142
views
Difference between implicit and explicit implementation of GetEnumerator() from IEnumerable
I have this class but I can't understand why it is useful to have one implementation as: public IEnumerator GetEnumerator() and the other as: IEnumerator IEnumerable.GetEnumerator(). I know that to ...
0
votes
0
answers
54
views
Debugging Enumerators and Coroutines: Use Reflection to get the current line of an iterator block
I am building a Coroutine wrapper system. I would like users to be able to jump to the Coroutine's last yield statement, or "state".
The wrapper is implemented as an Enumerator wrapper, that ...
0
votes
0
answers
32
views
When changing scenes, the Script that contains an Invoke() gives an error
I have an Invoke() inside a Coroutine. This Invoke() looks like this:
private IEnumerator aguardarResultado()
{
while(!_rigidbody.IsSleeping())
{
yield return null;
}
int ...
1
vote
1
answer
45
views
How to use Unity StopCoroutine when the Coroutine relies on mulitple conditions?
I have recently been messing with the Coroutine features in Unity and realised that I could not seem to stop a coroutine that relied on conditions with the StopCoroutine command.
My code is as follows:...
0
votes
1
answer
52
views
how to start IEnumerator again after SetActive(false);
I am trying to create a picture function in my game, and I want the picture frame to vanish after a couple seconds. After I did that, when I tried to take the picture again, it wont work. I am very ...
0
votes
1
answer
177
views
Unity Coroutine combined delay is longer than expected with multiple WaitForSeconds
I am starting a coroutine which iterates a loop number of times and waiting a certain time between each iteration. But complation of the loop takes way more longer than the expected. Here is the code:
...
-2
votes
1
answer
153
views
IEnumerator skips the code after yield return new WaitForSeconds
I am trying to use coroutines to spawn cubes in my game by following Unity Learn tutorials but altougj I did everything same as it is in the tutorial the code does not work and skips the code after ...
0
votes
1
answer
32
views
IEnumerator not triggering when start coroutine is called
So my code is supposed to print this out into the console after 3.5 seconds, but it never happens for some reason.
I have no idea what to try.
Here's my code:
using System.Collections;
using System....
0
votes
0
answers
50
views
How can I start a coroutine at the same time as executing a regular function?
I made a Reload() function that checks the current mag and ammo of a weapon and then reloads it, and I also want play sounds while I reload and so I made an IEnumerator to match the sounds with my ...
1
vote
0
answers
25
views
Always gets a blue screen for writing a specific IEnumerator method for a coroutine (Unity 2D, c#, script)
Every time I finally get my IEnumerator method for a coroutine finally able to return a value, I get a blue screen and my hierarchy is empty. Is there something wrong with my code so I get a blue ...
2
votes
3
answers
103
views
Nested IEnumerators not running as I expect
If I call Run() multiple times, I expect to see the messages "One", "Two" and "Three", but it's not what is happening, I can see the first one and then the MoveNext() ...
0
votes
1
answer
91
views
Unity C# Coroutine not functioning properly
I have a coroutine that is used to track time and score. Every 10 seconds, the score is updated and a sound is played, and every 6 seconds, there is another sound. When the time goes to 0 game ends. ...
0
votes
1
answer
847
views
Using a custom ref struct enumerator in a foreach loop
How can I use a custom ref struct enumerator to be implicitly used in a foreach loop?
I want to be able to do something like foreach (var el in span) {...} using my own ref struct enumerator. The ...
7
votes
1
answer
292
views
Why Enumerator MoveNext() returns 0
Why next code generates loop hangs?
var x = new
{
Items = new List<int> { 1, 2, 3 }.GetEnumerator()
};
while (x.Items.MoveNext())
Console.WriteLine(x.Items.Current);
If I get enumerator ...
0
votes
1
answer
257
views
Confusion over how to implement IEnumerable
I am new to IEnumerable in C# and am confused when reading about how to implement it from multiple sources.
Here is what I have gathered so far:
(1) source 1: If a class implements IEnumerable, it ...
0
votes
2
answers
57
views
How to keep current multiplier after multiplying your current multiplier by two for 30 seconds with a coroutine
As the title says I would like to give my player a temporary 2x multiplier and then take it away after. So far I have a button they click that sets their current multiplier x2 and then after 10 ...
0
votes
1
answer
247
views
What Is The Shortest WaitForSeconds Time Possible, Except 0?
Using yield return new WaitForSeconds(waitTime);
within an IEnumerator, what is the shortest wait time other than 0? I have tried using a float number and have tried as low as 0.00001f for the ...
2
votes
2
answers
162
views
Forward-only one-pass stateful IEnumerable<T> to IEnumerable<IEnumerable<T>> with no interim storage?
I want to take streamed IEnumerable values such as: (Tuples shown for illustration purposes. The actual application will be streaming DataRecords from a DataReader)
var tuples = new(int, int)[]
{
(...
1
vote
1
answer
3k
views
Error - 'Unable to cast object of type 'System.Collections.Generic.List`1[]' to type 'System.Collections.Generic.IEnumerable`[]'.'
I am new to API's and I am developing one (trying to) in VB.net and have followed this video - https://www.youtube.com/watch?v=nMGlaiNBbNU. although I am using Visitors instead of employees.
I have ...
0
votes
1
answer
303
views
.NET creating an IEnumerator on top of "GetEnumerator()" method from another class
I'm trying to create an IEnumerator based on the Directory.EnumerateFiles as you can see below. My enumerator works on top of Directory.EnumerateFiles by using LINQ .Select to convert the FileInfo ...
1
vote
1
answer
167
views
C# How to Serialize/Deserialize an IEnumerator from a Yield function (to Json?)
I'm trying to serialize/deserialize an IEnumerator generated from a function using yield.
I would like to serialize the IEnumerator at any iteration, I don't want to force it to generate all of it ...
3
votes
3
answers
794
views
foreach of IEnumerable<T> always calls non-generic Enumerator
I have created an object and implemented the interface IEnumerable<Options>.
If I try to loop through my object it is working fine but the variables aren't casted to a Options but object.
public ...
-4
votes
1
answer
64
views
How to convert IEnumerator to an arraylist efficiently, without looping trough the IEnumerator?
The software I'm using, Tekla Structures, returns an IEnumerator of all the filtered object of the database. It returns several hundreds of thousands object.
Looping trough the IEnumerator with ...
0
votes
2
answers
2k
views
How to get property value from IEnumerable<object>
I have a method which returns IEnumerable
public static IEnumerable<object> GetProps<T>(T obj)
{
var result = obj.GetType().GetProperties()
.Select(x => ...
0
votes
2
answers
64
views
Get a new move point, freeze her and move the object until it reaches the point
I'm trying to write logic when the player moves away from the summon further than 10f, the summon gets a random point around the player and moves towards it.
I already have a calculation of the ...
2
votes
1
answer
551
views
When is Dispose() of a class implementing IEnumerator<T> called automatically by Linq?
I'm studying IEnumerable<T> and IEnumerator<T>.
I wrote the code referring to this example.
Here's a part of the example code in the link that uses it:
var stringsFound =
from line in ...
1
vote
0
answers
388
views
Coroutine related functions dont work when I build the project
I have 2 scripts that feature Coroutines, and in the unity editor they work fine. But when i build the project, the funtions in both scripts start behaving weird (slow and late input).
This is one of ...
0
votes
0
answers
174
views
How To Animate Line Renderer When Multiple Points Are Clicked in Unity
I have multiple points on screen and when a player clicks them in correct order, it should animate a line between them. If player clicks on points faster than the line appear animation can go, next ...
0
votes
1
answer
30
views
Doubst about Managin player actions and cooldown time
So i got this action object witch contains a button, when i press that button the action coroutine starts, sets the cooldown of the action and enabled=false the button.
Im trying to implement a ...
0
votes
1
answer
497
views
How to make a Deconstructor for class that implements IEnumerable
I have a class that implements IEnumerable. It contains a GetEnumerator() method and a private class that implements IEnumerator. The Current() method of that class returns an object that is a ...
2
votes
1
answer
690
views
using fade out effect to load scene in Unity, but it doesn't work at all
Now I'm making C# script to load scene after fade out effect.
First scene has a panel and the tag of the panel is image.
The name of the second scene is EndingCredit.
But when I added this script to ...
2
votes
0
answers
18
views
Last IEnumerator in sequence not triggering
I have an IEnumerator that yield-returns to several others in sequence:
IEnumerator AttackSequence(HexCell target)
{
yield return LookAt(target.Position);
yield return RangedPhase(target);
...
0
votes
0
answers
205
views
How to implement IEnumerable in C# using generics
My code has an iterator inner class which inherits from IEnumerator interface and Vector outer class which inherits from IEnumerable and IComparable interfaces.
public class Vector<T> : ...
0
votes
3
answers
4k
views
How to exit from coroutine in unity in specific condition?
i have some problems with coroutines in unity. I want that my player when he gets to the door (when a collision occurs) to enter in the tower after 3 seconds, and if he moves within less than 3 ...
3
votes
2
answers
607
views
IEnumerators not continue from yield statement
So i've got a problem with IEnumerators with the yield return Talking call at the end of the options function. The talking function is then later set to yield return true when the text file reaches a ...
0
votes
1
answer
472
views
How to speed up foreach loop for IEnumerator
Little background
I am trying to use Intersystems IRIS Api
In case you want to see it.
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=BNETNAT_refapi#BNETNAT_refapi_iris-...
0
votes
0
answers
121
views
C# returning enumerator from generic recursive data structure using extension methods
I am trying to create an interface so that I can make a class recursive tree node data structure. That way, I can write generic extension methods which will deal with the generic tree traversal logic ...
-2
votes
1
answer
74
views
I am having problem with making my character Dash using Shift keys [duplicate]
Movement Move;
public float DashSpeed;
private float DashTime;
// Start is called before the first frame update
void Start()
{
Move=GetComponent<Movement>();
}
// Update is called once per ...
0
votes
1
answer
362
views
How do i fix my Unity 2D c# OnTriggerEnter2D delay?
Hello i have some Problems with my Teleport code for my unity 2d game
I'm trying to delay my Teleport for my fade screen but it doesn't work
also i need
other.transform.position = teleportTo.position;
...
0
votes
1
answer
110
views
How do I make a text be delayed after a question mark? (Unity)
I have this text with a typewriter effect and want it to have a bigger delay after a question mark. I have another code that works with commas and periods but that because I copied it. I tried making ...
0
votes
2
answers
466
views
How to make a custom Linked List using IEnumerable, IEnumerator
I'm trying to create a simple Linked List that allows me to iterate each element.
But when I try to iterate the list on the method GetReservation() the foreach imidiatly stops and I don't understand ...