Forum rules - please read before posting.

ActionPauseRandom (Waits a random amount within the described interval)

Hey, saw someone looking for custom action that I made a while ago, so I posted it here.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
 [System.Serializable]
 public class ActionPauseRandom : Action
 {
  public int parameterIDMin = -1;
        public int parameterIDMax = -1;
        public float timeToPauseMin;
        public float timeToPauseMax;

        public ActionPauseRandom ()
  {
   this.isDisplayed = true;
   category = ActionCategory.Engine;
   title = "Wait Random";
   description = "Waits a random time between the values continuing.";
  }

  override public void AssignValues (List<ActionParameter> parameters)
  {
   timeToPauseMin = AssignFloat (parameters, parameterIDMin, timeToPauseMin);
   timeToPauseMin = Mathf.Max (0f, timeToPauseMin);
            timeToPauseMax = AssignFloat(parameters, parameterIDMax, timeToPauseMax);
            timeToPauseMax = Mathf.Max(0f, timeToPauseMax);
        }
  
  override public float Run ()
  {
   if (!isRunning)
   {
    isRunning = true;
    return Random.Range(timeToPauseMin, timeToPauseMax);
   }
   else
   {
    isRunning = false;
    return 0f;
   }
  }

#if UNITY_EDITOR
  override public void ShowGUI (List<ActionParameter> parameters)
  {
   parameterIDMin = Action.ChooseParameterGUI ("Minimum wait time (s):", parameters, parameterIDMin, ParameterType.Float);
   if (parameterIDMax < 0)
   {
    timeToPauseMin = EditorGUILayout.FloatField ("Minimum wait time (s):", timeToPauseMin);
   }
            parameterIDMax = Action.ChooseParameterGUI ("Maximum wait time (s):", parameters, parameterIDMax, ParameterType.Float);
   if (parameterIDMax < 0)
   {
    timeToPauseMax = EditorGUILayout.FloatField ("Maximum wait time (s):", timeToPauseMax);
   }
   AfterRunningOption ();
  }
  
  public override string SetLabel ()
  {
   string labelAdd = " (" + timeToPauseMin+"-"+ timeToPauseMax + "s)";
   return labelAdd;
  }
    }
}

Comments

  • Nice! We should put it in the wikia :)
  • Hi, just letting you know I've posted you action in the AC Wikia. You can find it here. You are welcome to do any changes to it if you find anything you don't like or want to update or correct anything.

    Anyway, happy developing!
  • Okay, thanks. I made an attempt to add it to the wiki, but my browser was acting up and i couldn't properly write an article so thanks for the help. Maybe I'll come around to polishing that script a bit. (To block the max time from being below the min time for example.)
  • Cool, that'd be great :) Anyway, I do know there are some quirks to using the wikia. But the biggest issue I've seen is that the copy pasting is awful. They made their own code, and I'm not sure if it's for "security" or due to compatibility issues between sites but it often won't let you copy paste from other websites, even if you paste that in a notepad. 

    I've been thinking that sometimes it may have to do with the underlying text formatting. Because if you paste the text on a notepad or notepad+ document and then save, then it allows you to copy the text.But, besides this occasional issue, it's not that hard once you've done it once or twice. Just hit the contribute button near the top, the click Add page. 

    Though, there is one thing that people keep forgetting, which I think we should emphasize some more in the guide, and that's the Tag. People forget to put it and that way the page ends up floating in limbo until someone assigns it. Thankfully I've caught some articles like that and assigned the tag myself (else they don't show up in the list), but luckily we only have two tags right now: General and Integrations.

    Anyway, forget about my ranting, just remember you are welcome to make any changes to the article if you want. So, cheers!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.