Jump to content

Coroutine help?


Recommended Posts

I really don't know anything about coroutines. Never used them before. But I am trying to now, and having problems. I wrote this code based on the Unity docs. The coroutine starts, but only executes once, whereas it is supposed to continue indefinitely until told to stop.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using UnityEngine;
using KSPPluginFramework;
using TestFlightAPI;

namespace TestFlight
{
public class TestFlightFailure_FuelLeak : TestFlightFailureBase
{
/// <summary>
/// Triggers the failure controlled by the failure module
/// </summary>
public override void DoFailure()
{
Debug.Log("TestFlightFailure_FuelLeak: Failing part");
this.part.RequestResource("LiquidFuel", 50);
StartCoroutine("LeakFuel");
}

internal IEnumerator LeakFuel()
{
this.part.RequestResource("LiquidFuel", 5);
yield return new WaitForSeconds(1f);
}

/// <summary>
/// Asks the repair module if all condtions have been met for the player to attempt repair of the failure. Here the module can verify things such as the conditions (landed, eva, splashed), parts requirements, etc
/// </summary>
/// <returns><c>true</c> if this instance can attempt repair; otherwise, <c>false</c>.</returns>
public override bool CanAttemptRepair()
{
return true;
}

/// <summary>
/// Trigger a repair ATTEMPT of the module's failure. It is the module's responsability to take care of any consumable resources, data transmission, etc required to perform the repair
/// </summary>
/// <returns>Should return true if the failure was repaired, false otherwise</returns>
public override bool AttemptRepair()
{
StopCoroutine("LeakFuel");
return true;
}
}
}

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...