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.

58 lines
1.3KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Instantly rotates the target to face the given point or actor.
  8. /// </summary>
  9. class ActionSetDirection : ActionInstant
  10. {
  11. protected Vector3 value;
  12. protected Actor other;
  13. public ActionSetDirection(Vector3 tgtValue)
  14. : base()
  15. {
  16. value = tgtValue;
  17. }
  18. public ActionSetDirection(Vector2 tgtValue)
  19. : this((Vector3)tgtValue)
  20. {
  21. is2d = true;
  22. }
  23. public ActionSetDirection(Actor tgtActor)
  24. : base()
  25. {
  26. other = tgtActor;
  27. }
  28. /// <summary>
  29. /// Returns a copy of the action.
  30. /// </summary>
  31. public override ActionInstant clone()
  32. {
  33. return new ActionSetDirection(value);
  34. }
  35. /// <summary>
  36. /// This method is called at the action start.
  37. /// </summary>
  38. public override void start()
  39. {
  40. base.start();
  41. if (other != null)
  42. {
  43. value = other.transform.position;
  44. }
  45. if (is2d)
  46. {
  47. value.z = transform.position.z;
  48. }
  49. transform.rotation = Quaternion.LookRotation(transform.position - value);
  50. }
  51. }
  52. }