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.

67 lines
1.9 KiB

  1. using System.Collections;
  2. using UnityEngine;
  3. [CreateAssetMenu(menuName = "Major Project/Pick Ups/Shoot Block")]
  4. [System.Serializable]
  5. public class Shoot : LogicBlock
  6. {
  7. [SerializeField]
  8. [Header("Direction to shoot in")]
  9. private Direction Direction;
  10. [SerializeField]
  11. [Header("Projectile to Shoot")]
  12. private Projectile Projectile;
  13. private string prefabName;
  14. public override Block GetEndBlock(Block startBlock, Transform transform, LayerMask layerMask)
  15. {
  16. return startBlock;
  17. }
  18. protected override IEnumerator BlockLogic(Character player, float animationTime, bool useBlockDirection = false)
  19. {
  20. Projectile newProjectile = Instantiate(Projectile, player.transform.position, player.transform.rotation);
  21. Vector3 direction = Direction.ToVector(player.transform);
  22. yield return newProjectile.StartCoroutine(newProjectile.ProjectileLogic(player, animationTime, direction));
  23. Destroy(newProjectile.gameObject);
  24. }
  25. public override void CopyToken(BlockToken token)
  26. {
  27. base.CopyToken(token);
  28. prefabName = ((ShotToken)token).prefabName;
  29. Projectile = Resources.Load<GameObject>(((ShotToken)token).prefabName)?.GetComponent<Projectile>();
  30. Direction = ((ShotToken)token).direction;
  31. }
  32. public override BlockToken ToToken(BlockToken token = null)
  33. {
  34. if (token == null)
  35. token = new ShotToken(this);
  36. Debug.Log(base.ToToken(token).GetType().Name);
  37. ShotToken retVal = (ShotToken)base.ToToken(token);
  38. retVal.direction = Direction;
  39. if (Projectile != null)
  40. retVal.prefabName = Projectile.gameObject.name;
  41. else
  42. retVal.prefabName = prefabName;
  43. return retVal;
  44. }
  45. }
  46. [System.Serializable]
  47. public class ShotToken : BlockToken
  48. {
  49. public Direction direction;
  50. public string prefabName;
  51. public ShotToken(LogicBlock block) : base(block) { }
  52. }