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.

62 lines
1.8 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. 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. Projectile = Resources.Load<GameObject>(((ShotToken)token).prefabName).GetComponent<Projectile>();
  29. Direction = ((ShotToken)token).direction;
  30. }
  31. public override BlockToken ToToken(BlockToken token = null)
  32. {
  33. if (token == null)
  34. token = new ShotToken(this);
  35. Debug.Log(base.ToToken(token).GetType().Name);
  36. ShotToken retVal = (ShotToken)base.ToToken(token);
  37. retVal.direction = Direction;
  38. retVal.prefabName = Projectile.gameObject.name;
  39. return retVal;
  40. }
  41. }
  42. [System.Serializable]
  43. public class ShotToken : BlockToken
  44. {
  45. public Direction direction;
  46. public string prefabName;
  47. public ShotToken(LogicBlock block) : base(block) { }
  48. }