You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

43 line
1.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Moves in the given direction for the given amount of seconds.
  8. /// </summary>
  9. class ActionMoveForward : ActionInterval
  10. {
  11. protected float speed;
  12. protected Vector3 delta;
  13. public ActionMoveForward(float targetSpeed, float targetDuration)
  14. : base(targetDuration)
  15. {
  16. speed = targetSpeed;
  17. }
  18. public override ActionInstant Clone()
  19. {
  20. return new ActionMoveForward(speed, duration);
  21. }
  22. public override ActionInstant Reverse()
  23. {
  24. return new ActionMoveForward(speed * -1F, duration);
  25. }
  26. public override void Start()
  27. {
  28. base.Start();
  29. delta = speed * transform.forward;
  30. }
  31. public override void Step(float dt)
  32. {
  33. float d = dt / duration;
  34. transform.Translate(delta * d, Space.World);
  35. }
  36. }
  37. }