FANDOM


Note: This action allows you to wait a randomized amount of time between a time range.

There are two ways to create the script:

1 Create a blank text file, paste the code, then rename the file to the name of the class and change the extension to .cs (ActionPauseRandom.cs).

Or

2. Create a script inside unity in the library tab named as mentioned before, then just replace the whole text in the file.

Then, just drop this in the Actions folder in AC or make your own custom Action folder, go to the Actions manager in AC and then set the folder for custom action in there.

Here's code:

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;
  }
 #endif
     }
 }

[Code provided by user: Teshla]

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.