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.

734 lines
27 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using Networking.Server;
  7. public class Character : MonoBehaviour
  8. {
  9. public enum Animation { Walk, Run, Jump, Sit, Attack, Hit }
  10. public string nextScene;
  11. Animator characterAnimator;
  12. public bool isTuteLevel = false;
  13. public bool inWater = false; //Am I in the water?
  14. public bool inPit = false; //Did I fall into a pit?
  15. public bool stuck = false; //Am I still stuck?
  16. public bool justMoved = false; //Was the logic block I just executed a move command?
  17. #region Inspector Fields
  18. [SerializeField]
  19. [Tooltip("Will move to this block at start, else will try and find a block below")]
  20. private Block _currentBlock;
  21. [SerializeField]
  22. [Tooltip("Layers to ignore when checking for blocks")]
  23. public LayerMask Ignore;
  24. [Tooltip("Current Inventory of the player")]
  25. public Inventory Inventory;
  26. public bool CloneInventoryOnStart = false;
  27. [Tooltip("How many lives to start out with")]
  28. public int lives = 3;
  29. [SerializeField]
  30. [Tooltip("Character to display")]
  31. private string CharacterModel = "Bear";
  32. [SerializeField]
  33. public ClientData ClientLink;
  34. [SerializeField]
  35. private TMPro.TextMeshPro BlockTitlePrefab;
  36. #endregion Inspector Fields
  37. #region Read Only
  38. public Block CurrentBlock { get { return _currentBlock; } }
  39. #endregion Read Only
  40. #region Unity Functions
  41. private void Start()
  42. {
  43. if (Inventory != null && CloneInventoryOnStart)
  44. Inventory = Inventory.Clone(Inventory);
  45. //If no starting block find one below it
  46. if (_currentBlock == null)
  47. Block.isBlockAtPosition(transform.position + Vector3.down / 2, 1, ~Ignore, out _currentBlock);
  48. //move to starting block
  49. transform.position = _currentBlock.VisualPosition;
  50. //get character string from player replace from "Bear"
  51. GameObject prefab = Resources.Load(CharacterModel) as GameObject;
  52. GameObject animal = Instantiate(prefab, this.gameObject.transform);
  53. characterAnimator = GetComponentInChildren<Animator>();
  54. }
  55. #endregion Unity Functions
  56. #region Class Implementation
  57. public void Initialise(Block startingBlock, Inventory inventory, string Character)
  58. {
  59. _currentBlock = startingBlock;
  60. Inventory = inventory;
  61. CharacterModel = Character;
  62. }
  63. public void DisplayBlock(LogicBlock block)
  64. {
  65. if (isTuteLevel == false)
  66. {
  67. if (BlockTitlePrefab == null)
  68. return;
  69. TMPro.TextMeshPro temp = Instantiate(BlockTitlePrefab.gameObject).GetComponent<TMPro.TextMeshPro>();
  70. temp.text = block.DisplayName;
  71. temp.color = ClientLink.Color;
  72. temp.transform.position = transform.position + (Vector3.one * 0.25f);
  73. temp.transform.rotation = Quaternion.LookRotation(temp.transform.position - Camera.main.transform.position);
  74. }
  75. }
  76. public IEnumerator MoveToBlock(Block target, Animation animation, float time)
  77. {
  78. float startTime = Time.time;
  79. Vector3 moveDirection = Vector3.ProjectOnPlane(target.position - _currentBlock.position, Vector3.up).normalized;
  80. _currentBlock.OnLeftByPlayer(this);
  81. System.Func<float, float> yFunction = null;
  82. if (animation == Animation.Jump)
  83. yFunction = (t) => Mathf.Sin((Mathf.PI * t));
  84. StartAnimation(animation, time);
  85. yield return StartCoroutine(LerpToBlock(target.VisualPosition, time * 0.8f, yFunction));
  86. _currentBlock= target;
  87. yield return StartCoroutine (_currentBlock.OnWalkedOnByPlayer(this,moveDirection));
  88. yield return new WaitForSeconds(time - (Time.time - startTime));
  89. StopAnimation(animation);
  90. }
  91. public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true)
  92. {
  93. System.Func<float, float> yFunction = null;
  94. if (animation == Animation.Jump)
  95. yFunction = (t) => Mathf.Sin((Mathf.PI * t));
  96. Vector3 _endDir = isLocal ? direction.ToVector(transform) : direction.ToVector();
  97. StartAnimation(animation, time);
  98. yield return StartCoroutine(LerpToRotation(_endDir, time * 0.8f, yFunction));
  99. StopAnimation(animation);
  100. }
  101. private IEnumerator LerpToBlock(Vector3 target, float time, System.Func<float, float> heightOffset = null)
  102. {
  103. Vector3 _startPos = transform.position;
  104. Vector3 _endPos = target;
  105. Vector3 _newPos;
  106. float elapsedTime = 0;
  107. while (elapsedTime / time < 1)
  108. {
  109. _newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time));
  110. if (heightOffset != null)
  111. _newPos.y += heightOffset(elapsedTime / time);
  112. transform.position = _newPos;
  113. yield return new WaitForEndOfFrame();
  114. elapsedTime += Time.deltaTime;
  115. }
  116. _newPos = _endPos;
  117. if (heightOffset != null)
  118. _newPos.y += heightOffset(1);
  119. transform.position = _newPos;
  120. }
  121. private IEnumerator LerpToRotation(Vector3 target, float time, System.Func<float, float> heightOffset = null)
  122. {
  123. Vector3 _startDir = transform.forward;
  124. Vector3 _endDir = target;
  125. Vector3 _startPos = transform.position;
  126. float elapsedTime = 0;
  127. while (elapsedTime / time < 1)
  128. {
  129. transform.forward = Vector3.Slerp(_startDir, _endDir, (elapsedTime / time));
  130. if (heightOffset != null)
  131. transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time);
  132. yield return new WaitForEndOfFrame();
  133. elapsedTime += Time.deltaTime;
  134. }
  135. transform.forward = target;
  136. if (heightOffset != null)
  137. transform.position = _startPos + Vector3.up * heightOffset(1);
  138. }
  139. public void StartAnimation(Animation animation,float speed = 1)
  140. {
  141. characterAnimator.SetFloat("AnimationSpeed", (1 / speed));
  142. switch (animation)
  143. {
  144. case Animation.Walk:
  145. characterAnimator.SetBool("isWalking", true);
  146. break;
  147. case Animation.Run:
  148. characterAnimator.SetBool("isRunning", true);
  149. break;
  150. case Animation.Sit:
  151. characterAnimator.SetBool("isSitting", true);
  152. break;
  153. case Animation.Jump:
  154. characterAnimator.SetTrigger("Jump");
  155. break;
  156. case Animation.Attack:
  157. characterAnimator.SetTrigger("Attack");
  158. break;
  159. case Animation.Hit:
  160. characterAnimator.SetTrigger("Hit");
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. public void StopAnimation(Animation animation)
  167. {
  168. characterAnimator.SetFloat("AnimationSpeed", 1f);
  169. switch (animation)
  170. {
  171. case Animation.Walk:
  172. characterAnimator.SetBool("isWalking", false);
  173. break;
  174. case Animation.Run:
  175. characterAnimator.SetBool("isRunning", false);
  176. break;
  177. case Animation.Sit:
  178. characterAnimator.SetBool("isSitting", false);
  179. break;
  180. }
  181. }
  182. public void respawnCharacter()
  183. {
  184. /* Will introduce more complex criteria for choosing where to respawn the player in future
  185. * For now: if the square one back (x =- 1) from the pit is walkable and unoccupied, then put them there
  186. * Otherwise, try the next square back, etc, until we find an available one
  187. */
  188. Block currentBlock = null;
  189. //We start from the position of our pit, at ground level
  190. Vector3 currentPos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
  191. Debug.Log("Commencing respawn");
  192. //Hardcoding the number of iterations for now for simplicity, should change this later
  193. for (int i = 0; i < 100; i++)
  194. {
  195. //First we check one back
  196. currentPos.x -= 1;
  197. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  198. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  199. {
  200. Debug.Log("Block exists");
  201. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  202. {
  203. Debug.Log("Block is walkable");
  204. //Don't yet have a check for whether it's occupied
  205. break; //If it is, we stop here
  206. }
  207. }
  208. //If the block one back isn't an option, we check to the left and right
  209. currentPos.z += 1;
  210. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  211. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  212. {
  213. Debug.Log("Block exists");
  214. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  215. {
  216. Debug.Log("Block is walkable");
  217. //Don't yet have a check for whether it's occupied
  218. break; //If it is, we stop here
  219. }
  220. }
  221. currentPos.z -= 2;
  222. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  223. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  224. {
  225. Debug.Log("Block exists");
  226. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  227. {
  228. Debug.Log("Block is walkable");
  229. //Don't yet have a check for whether it's occupied
  230. break; //If it is, we stop here
  231. }
  232. }
  233. //If we've gotten this far and haven't found an available spot, we move back a row and try again
  234. currentPos.z += 1;
  235. }
  236. //Having found our target block, we move the character there
  237. if (currentBlock != null)
  238. {
  239. this.transform.position = currentBlock.VisualPosition;
  240. this.inPit = false;
  241. this._currentBlock = currentBlock;
  242. Debug.Log("Moved " + this.name + " to "
  243. + this.transform.position.x + ", "
  244. + this.transform.position.y + ", "
  245. + this.transform.position.z + ", "
  246. + " inPit = " + inPit);
  247. }
  248. else
  249. {
  250. Debug.Log("Failed to find anywhere to put " + this.name);
  251. }
  252. }
  253. /// <summary>
  254. /// Upon collision with a floating block, collect its
  255. /// Upon collision with the end portal, end of level
  256. /// </summary>
  257. /// <param name="other">name of collided object</param>
  258. void OnTriggerEnter(Collider other)
  259. {
  260. Collectable collectable = other.GetComponentInChildren<Collectable>();
  261. if (collectable != null)
  262. {
  263. collectable.OnCollect(this);
  264. }
  265. if (other.gameObject.name == "collect_sphere")
  266. {
  267. other.gameObject.SetActive(false);
  268. //player.collected +=1;
  269. }
  270. if (other.gameObject.name == "End Portal")
  271. {
  272. other.GetComponent<Collider>().enabled = false;
  273. SceneManager.LoadScene(nextScene);
  274. }
  275. }
  276. /// <summary>
  277. /// Rotates to point in specific direction based on current direction
  278. /// </summary>
  279. /// <param name="direction">Local direction to point</param>
  280. public void Rotate(Direction direction, float speed)
  281. {
  282. StartCoroutine(rotateCoroutine(direction, transform, speed, 0.15f));
  283. //transform.forward = direction.ToVector(transform);
  284. }
  285. public void RotateHalf(Direction direction, float speed)
  286. {
  287. StartCoroutine(rotateHalfCoroutine(direction, transform, speed, 0.15f));
  288. //transform.forward = direction.ToVector(transform);
  289. }
  290. /// <summary>
  291. /// Jumps in specefied direction, picks between Long Jump and Jumping up
  292. /// </summary>
  293. /// <param name="direction">Direction to Jump</param>
  294. public void Jump(Direction direction, float speed)
  295. {
  296. //if there is a block infront JumpUp else LongJump
  297. if (Block.isBlockAtPosition(_currentBlock.position + direction.ToVector(transform) + Vector3.up, 1, ~Ignore))
  298. JumpUp(direction, speed);
  299. else
  300. JumpLong(direction, speed);
  301. }
  302. #endregion Class Implementation
  303. #region Private Functions
  304. /// <summary>
  305. /// Jumps up obstacle of specific height. Jumps as high as possible
  306. /// </summary>
  307. /// <param name="direction">Direction of obstacle</param>
  308. /// <param name="height">max height</param>
  309. private void JumpUp(Direction direction, float speed, int height = 1)
  310. {
  311. //setting up variables
  312. Vector3 position; // position wanted
  313. Block hit; //output of block detection
  314. Block moveTo = _currentBlock; //block we'll actually move to
  315. //Check blocks in going up then move to the heighest walkable one
  316. for (int i = 0; i <= height; i++)
  317. {
  318. //next position up the tower
  319. position = _currentBlock.position + direction.ToVector(transform) + (Vector3.up * i);
  320. //if block is walkable set it to last known position
  321. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  322. moveTo = hit;
  323. }
  324. //set current block && move
  325. _currentBlock = moveTo;
  326. StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f));
  327. //transform.position = CurrentBlock.VisualPosition;
  328. }
  329. /// <summary>
  330. /// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction
  331. /// </summary>
  332. /// <param name="direction">Direction to Jump</param>
  333. /// <param name="Distance">Max distance</param>
  334. private void JumpLong(Direction direction, float speed, int Distance = 2)
  335. {
  336. //setting up variables
  337. Vector3 position; // position wanted
  338. Block hit; //output of block detection
  339. Block moveTo = _currentBlock; //block we'll actually move to
  340. //Check blocks in front until we hit an obstruction or went the distance
  341. for (int i = 1; i <= Distance; i++)
  342. {
  343. //Next position to MoveTo
  344. position = _currentBlock.position + (direction.ToVector(transform) * i);
  345. //if jump is obstructed, stop and go to last known block
  346. if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore))
  347. break;
  348. //If block at Position is walkable set it to last known position
  349. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  350. moveTo = hit;
  351. //else if block down one is walkable
  352. else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  353. moveTo = hit;
  354. }//end for
  355. //Set Current Block and move
  356. _currentBlock = moveTo;
  357. StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f));
  358. //transform.position = CurrentBlock.VisualPosition;
  359. }
  360. #endregion Private Functions
  361. #region Depricated
  362. IEnumerator JumpCoroutine(Block Target, Transform Current, float time, float heightMax)
  363. {
  364. float elapsedTime = 0;
  365. Vector3 startPosition = Current.position;
  366. time *= 0.8f;
  367. characterAnimator.Play("Jump Inplace");
  368. yield return new WaitForSeconds(0.15f);
  369. while (elapsedTime < time)
  370. {
  371. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  372. //transform.position += yValue((elapsedTime / time), heightMax);
  373. yield return new WaitForEndOfFrame();
  374. elapsedTime += Time.deltaTime;
  375. }
  376. transform.position = Target.VisualPosition;
  377. }
  378. IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax)
  379. {
  380. float elapsedTime = 0;
  381. Vector3 startPosition = Current.position;
  382. time *= 0.8f;
  383. characterAnimator.Play("Walk");
  384. yield return new WaitForSeconds(0.05f);
  385. while (elapsedTime < time)
  386. {
  387. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  388. yield return new WaitForEndOfFrame();
  389. elapsedTime += Time.deltaTime;
  390. }
  391. transform.position = Target.VisualPosition;
  392. }
  393. IEnumerator MoveConveyorForwardCoroutine(Block Target, Transform Current, float time, float heightMax)
  394. {
  395. float elapsedTime = 0;
  396. Vector3 startPosition = Current.position;
  397. Vector3 charEndPosition = new Vector3(Current.position.x + 1.0f, Current.position.y, Current.position.z);
  398. time *= 0.8f;
  399. yield return new WaitForSeconds(0.05f);
  400. while (elapsedTime < time)
  401. {
  402. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  403. yield return new WaitForEndOfFrame();
  404. elapsedTime += Time.deltaTime;
  405. }
  406. Current.position = charEndPosition;
  407. }
  408. IEnumerator MoveConveyorBackwardCoroutine(Block Target, Transform Current, float time, float heightMax)
  409. {
  410. float elapsedTime = 0;
  411. Vector3 startPosition = Current.position;
  412. Vector3 charEndPosition = new Vector3(Current.position.x - 1.0f, Current.position.y, Current.position.z);
  413. time *= 0.8f;
  414. yield return new WaitForSeconds(0.05f);
  415. while (elapsedTime < time)
  416. {
  417. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  418. yield return new WaitForEndOfFrame();
  419. elapsedTime += Time.deltaTime;
  420. }
  421. Current.position = charEndPosition;
  422. }
  423. IEnumerator MoveConveyorLeftCoroutine(Block Target, Transform Current, float time, float heightMax)
  424. {
  425. float elapsedTime = 0;
  426. Vector3 startPosition = Current.position;
  427. Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f);
  428. time *= 0.8f;
  429. yield return new WaitForSeconds(0.05f);
  430. while (elapsedTime < time)
  431. {
  432. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  433. yield return new WaitForEndOfFrame();
  434. elapsedTime += Time.deltaTime;
  435. }
  436. Current.position = charEndPosition;
  437. }
  438. IEnumerator MoveConveyorRightCoroutine(Block Target, Transform Current, float time, float heightMax)
  439. {
  440. float elapsedTime = 0;
  441. Vector3 startPosition = Current.position;
  442. Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f);
  443. time *= 0.8f;
  444. yield return new WaitForSeconds(0.05f);
  445. while (elapsedTime < time)
  446. {
  447. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  448. yield return new WaitForEndOfFrame();
  449. elapsedTime += Time.deltaTime;
  450. }
  451. Current.position = charEndPosition;
  452. }
  453. IEnumerator PushLeftCoroutine(Transform Current, float time)
  454. {
  455. float elapsedTime = 0;
  456. Vector3 startPosition = Current.transform.position;
  457. Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f);
  458. time *= 0.8f;
  459. yield return new WaitForSeconds(0.05f);
  460. while (elapsedTime < time)
  461. {
  462. Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  463. yield return new WaitForEndOfFrame();
  464. elapsedTime += Time.deltaTime;
  465. }
  466. Current.position = endPosition;
  467. }
  468. IEnumerator PushRightCoroutine(Transform Current, float time)
  469. {
  470. float elapsedTime = 0;
  471. Vector3 startPosition = Current.transform.position;
  472. Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f);
  473. time *= 0.8f;
  474. yield return new WaitForSeconds(0.05f);
  475. while (elapsedTime < time)
  476. {
  477. Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  478. yield return new WaitForEndOfFrame();
  479. elapsedTime += Time.deltaTime;
  480. }
  481. Current.position = endPosition;
  482. }
  483. IEnumerator MoveDownCoroutine(Block Target, Transform Current, float time, float heightMax)
  484. {
  485. float elapsedTime = 0;
  486. Vector3 startPosition = Current.position;
  487. time *= 0.8f;
  488. characterAnimator.Play("Walk");
  489. while (elapsedTime < time)
  490. {
  491. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  492. //transform.position += yValue((elapsedTime / time), heightMax);
  493. yield return new WaitForEndOfFrame();
  494. elapsedTime += Time.deltaTime;
  495. }
  496. transform.position = Target.VisualPosition;
  497. }
  498. IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax)
  499. {
  500. float elapsedTime = 0;
  501. time *= 0.8f;
  502. Vector3 endDirection = direction.ToVector(Current);
  503. Vector3 startDirection = Current.forward;
  504. while (elapsedTime < time)
  505. {
  506. characterAnimator.Play("Jump");
  507. transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time));
  508. yield return new WaitForEndOfFrame();
  509. elapsedTime += Time.deltaTime;
  510. }
  511. transform.forward = endDirection;
  512. }
  513. IEnumerator rotateHalfCoroutine(Direction direction, Transform Current, float time, float heightMax)
  514. {
  515. float elapsedTime = 0;
  516. time *= 0.8f;
  517. Vector3 endDirection = (direction.ToVector(Current) + Current.forward).normalized;
  518. Vector3 startDirection = Current.forward;
  519. while (elapsedTime < time)
  520. {
  521. characterAnimator.Play("Jump");
  522. transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time));
  523. yield return new WaitForEndOfFrame();
  524. elapsedTime += Time.deltaTime;
  525. }
  526. transform.forward = endDirection;
  527. }
  528. /// <summary>
  529. /// Moves one block in specefied direction, Can walk off obstacles
  530. /// </summary>
  531. /// <param name="direction">direction to walk</param>
  532. /// <remarks>Technically is same as JumpLong(1) but kept seperate to avoid confusion</remarks>
  533. public void Move(Direction direction, float speed)
  534. {
  535. //setting up variables
  536. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  537. Block hit; //output of block detection
  538. Block moveTo = _currentBlock; //block we'll actually move to
  539. //if move is obstucted no where to move
  540. if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore))
  541. return;
  542. //If block at Position is walkable set it to moveTo
  543. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  544. {
  545. moveTo = hit;
  546. _currentBlock = moveTo;
  547. StartCoroutine(MoveCoroutine(_currentBlock, transform, speed, 0.3f));
  548. }
  549. //else if block down one is walkable
  550. else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  551. {
  552. moveTo = hit;
  553. _currentBlock = moveTo;
  554. StartCoroutine(MoveDownCoroutine(_currentBlock, transform, speed, 0.3f));
  555. }
  556. }
  557. public void conveyorMoveForward(Direction direction, float speed)
  558. {
  559. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  560. Block hit; //output of block detection
  561. Block moveTo = _currentBlock; //block we'll actually move to
  562. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  563. {
  564. moveTo = hit;
  565. _currentBlock = moveTo;
  566. StartCoroutine(MoveConveyorForwardCoroutine(_currentBlock, transform, speed, 0.3f));
  567. }
  568. }
  569. public void conveyorMoveBackward(Direction direction, float speed)
  570. {
  571. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  572. Block hit; //output of block detection
  573. Block moveTo = _currentBlock; //block we'll actually move to
  574. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  575. {
  576. moveTo = hit;
  577. _currentBlock = moveTo;
  578. StartCoroutine(MoveConveyorBackwardCoroutine(_currentBlock, transform, speed, 0.3f));
  579. }
  580. }
  581. public void conveyorMoveLeft(Direction direction, float speed)
  582. {
  583. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  584. Block hit; //output of block detection
  585. Block moveTo = _currentBlock; //block we'll actually move to
  586. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  587. {
  588. moveTo = hit;
  589. _currentBlock = moveTo;
  590. StartCoroutine(MoveConveyorLeftCoroutine(_currentBlock, transform, speed, 0.3f));
  591. }
  592. }
  593. public void conveyorMoveRight(Direction direction, float speed)
  594. {
  595. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  596. Block hit; //output of block detection
  597. Block moveTo = _currentBlock; //block we'll actually move to
  598. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  599. {
  600. moveTo = hit;
  601. _currentBlock = moveTo;
  602. StartCoroutine(MoveConveyorRightCoroutine(_currentBlock, transform, speed, 0.3f));
  603. }
  604. }
  605. public void CannonRMove(float speed)
  606. {
  607. Direction direction = Direction.Right;
  608. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  609. Block hit; //output of block detection
  610. Block moveTo = _currentBlock; //block we'll actually move to
  611. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  612. {
  613. moveTo = hit;
  614. _currentBlock = moveTo;
  615. StartCoroutine(PushRightCoroutine(transform, speed));
  616. }
  617. }
  618. public void CannonLMove(float speed)
  619. {
  620. Direction direction = Direction.Left;
  621. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  622. Block hit; //output of block detection
  623. Block moveTo = _currentBlock; //block we'll actually move to
  624. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  625. {
  626. moveTo = hit;
  627. _currentBlock = moveTo;
  628. StartCoroutine(PushLeftCoroutine(transform, speed));
  629. }
  630. }
  631. #endregion Depricated
  632. }