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.

70 lines
2.0 KiB

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