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.

47 lines
1.1KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Moves to the given point for the given amount of seconds.
  8. /// </summary>
  9. class ActionMoveTo : ActionInterval
  10. {
  11. protected Vector3 value;
  12. protected Vector3 path;
  13. public ActionMoveTo(Vector3 targetValue, float targetDuration)
  14. : base(targetDuration)
  15. {
  16. value = targetValue;
  17. }
  18. public ActionMoveTo(Vector2 targetValue, float targetDuration)
  19. : this((Vector3)targetValue, targetDuration)
  20. {
  21. locks = Axises.z;
  22. }
  23. public override ActionInstant Clone()
  24. {
  25. return new ActionMoveBy(value, duration);
  26. }
  27. public override void Start()
  28. {
  29. base.Start();
  30. if (locks != Axises.none)
  31. LockAxises(ref value);
  32. path = value - transform.position;
  33. }
  34. public override void Step(float dt)
  35. {
  36. float d = dt / duration;
  37. Vector3 target = path * d;
  38. transform.Translate(target, Space.World);
  39. }
  40. }
  41. }