From b02e6c0cd2ac471126f601e722060098f3796c33 Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Thu, 28 Mar 2019 16:32:15 +1100 Subject: [PATCH] fixed character + added inventories --- Assets/Data/Inventory/Tutorial1.asset | 3 + Assets/Data/Inventory/Tutorial1.asset.meta | 8 + Assets/Data/Inventory/Tutorial2.asset | 3 + Assets/Data/Inventory/Tutorial2.asset.meta | 8 + Assets/Data/Inventory/Tutorial3.asset | 3 + Assets/Data/Inventory/Tutorial3.asset.meta | 8 + Assets/Data/Inventory/Tutorial4.asset | 3 + Assets/Data/Inventory/Tutorial4.asset.meta | 8 + Assets/Scripts/Character.cs | 301 +++++++++++---------- 9 files changed, 197 insertions(+), 148 deletions(-) create mode 100644 Assets/Data/Inventory/Tutorial1.asset create mode 100644 Assets/Data/Inventory/Tutorial1.asset.meta create mode 100644 Assets/Data/Inventory/Tutorial2.asset create mode 100644 Assets/Data/Inventory/Tutorial2.asset.meta create mode 100644 Assets/Data/Inventory/Tutorial3.asset create mode 100644 Assets/Data/Inventory/Tutorial3.asset.meta create mode 100644 Assets/Data/Inventory/Tutorial4.asset create mode 100644 Assets/Data/Inventory/Tutorial4.asset.meta diff --git a/Assets/Data/Inventory/Tutorial1.asset b/Assets/Data/Inventory/Tutorial1.asset new file mode 100644 index 0000000..4b381a6 --- /dev/null +++ b/Assets/Data/Inventory/Tutorial1.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:655ef64cdee98ecd6c8f7cb75875072108b55815051571d97361c5f076caaafb +size 522 diff --git a/Assets/Data/Inventory/Tutorial1.asset.meta b/Assets/Data/Inventory/Tutorial1.asset.meta new file mode 100644 index 0000000..5d57179 --- /dev/null +++ b/Assets/Data/Inventory/Tutorial1.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 808f6e35b72adbf47a19927d1f3efd35 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Inventory/Tutorial2.asset b/Assets/Data/Inventory/Tutorial2.asset new file mode 100644 index 0000000..61e7aff --- /dev/null +++ b/Assets/Data/Inventory/Tutorial2.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d51d42988dcad792d1a26c5f4362d573a4c660311e530fb4244d3823c245e9d +size 522 diff --git a/Assets/Data/Inventory/Tutorial2.asset.meta b/Assets/Data/Inventory/Tutorial2.asset.meta new file mode 100644 index 0000000..033f106 --- /dev/null +++ b/Assets/Data/Inventory/Tutorial2.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d342ea734412a4b40bb6096d5cafc2fb +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Inventory/Tutorial3.asset b/Assets/Data/Inventory/Tutorial3.asset new file mode 100644 index 0000000..7de2699 --- /dev/null +++ b/Assets/Data/Inventory/Tutorial3.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b4b715f269c24473655cff17cd3b3a635111b91b4c5581be94c7686a8c18308 +size 633 diff --git a/Assets/Data/Inventory/Tutorial3.asset.meta b/Assets/Data/Inventory/Tutorial3.asset.meta new file mode 100644 index 0000000..7f2157f --- /dev/null +++ b/Assets/Data/Inventory/Tutorial3.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 26baa66216f4923448239677997ac13d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Inventory/Tutorial4.asset b/Assets/Data/Inventory/Tutorial4.asset new file mode 100644 index 0000000..a0bb5d4 --- /dev/null +++ b/Assets/Data/Inventory/Tutorial4.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d033311011d9927de9bedbf400dd7f1559bce5b5ebfb78681bfdc37685d9e16b +size 744 diff --git a/Assets/Data/Inventory/Tutorial4.asset.meta b/Assets/Data/Inventory/Tutorial4.asset.meta new file mode 100644 index 0000000..c22bcfd --- /dev/null +++ b/Assets/Data/Inventory/Tutorial4.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b06e54ffefee9e549a8e1652d5af07f9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index fa32887..f4f4a4a 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -6,182 +6,187 @@ using UnityEngine.SceneManagement; public class Character : MonoBehaviour { - public string nextScene; + public string nextScene; #region Inspector Fields [SerializeField] private Inventory startingInventory; - [SerializeField] - [Tooltip ("Will move to this block at start, else will try and find a block below")] - private Block CurrentBlock; + [SerializeField] + [Tooltip("Will move to this block at start, else will try and find a block below")] + private Block CurrentBlock; - [SerializeField] - [Tooltip ("Layers to ignore when checking for blocks")] - private LayerMask Ignore; + [SerializeField] + [Tooltip("Layers to ignore when checking for blocks")] + private LayerMask Ignore; [Tooltip("Current Inventory of the player")] public Inventory Inventory; - #endregion Inspector Fields + #endregion Inspector Fields - #region Unity Functions + #region Unity Functions - private void Awake () - { - Inventory.Clone(startingInventory); + private void Awake() + { + if (Inventory != null || startingInventory != null) + Inventory.Clone(startingInventory); - //If no starting block find one below it - if (CurrentBlock == null) - Block.isBlockAtPosition (transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock); + //If no starting block find one below it + if (CurrentBlock == null) + Block.isBlockAtPosition(transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock); - //move to starting block - transform.position = CurrentBlock.VisualPosition; - } + //move to starting block + transform.position = CurrentBlock.VisualPosition; + } - #endregion Unity Functions + #endregion Unity Functions - #region Class Implementation + #region Class Implementation - /// - /// Moves one block in specefied direction, Can walk off obstacles - /// - /// direction to walk - /// Technically is same as JumpLong(1) but kept seperate to avoid confusion - public void Move (Direction direction) - { - //setting up variables - Vector3 position = CurrentBlock.position + direction.ToVector (transform); // position wanted - Block hit; //output of block detection - Block moveTo = CurrentBlock; //block we'll actually move to + /// + /// Moves one block in specefied direction, Can walk off obstacles + /// + /// direction to walk + /// Technically is same as JumpLong(1) but kept seperate to avoid confusion + public void Move(Direction direction) + { + //setting up variables + Vector3 position = CurrentBlock.position + direction.ToVector(transform); // position wanted + Block hit; //output of block detection + Block moveTo = CurrentBlock; //block we'll actually move to - //if move is obstucted no where to move - if (Block.isBlockAtPosition (position + Vector3.up, 1, ~Ignore)) - return; + //if move is obstucted no where to move + if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) + return; - //If block at Position is walkable set it to moveTo - if (Block.isBlockAtPosition (position, 1, ~Ignore, out hit) && hit.isWalkable (~Ignore)) - moveTo = hit; + //If block at Position is walkable set it to moveTo + if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) + moveTo = hit; //else if block down one is walkable - else if (Block.isBlockAtPosition (position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable (~Ignore)) - moveTo = hit; - - //set current block && move - CurrentBlock = moveTo; - transform.position = CurrentBlock.VisualPosition; - } - - /// - /// Upon collision with a floating block, collect its - /// Upon collision with the end portal, end of level - /// - /// name of collided object - void OnTriggerEnter (Collider other) - { + else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) + moveTo = hit; + + //set current block && move + CurrentBlock = moveTo; + transform.position = CurrentBlock.VisualPosition; + } + + /// + /// Upon collision with a floating block, collect its + /// Upon collision with the end portal, end of level + /// + /// name of collided object + void OnTriggerEnter(Collider other) + { Collectable collectable = other.GetComponentInChildren(); - if (other != null) { + if (collectable != null) + { collectable.OnCollect(this); - } - if (other.gameObject.name == "End Portal") { - other.GetComponent ().enabled = false; - Debug.Log ("You finished this level!"); - SceneManager.LoadScene (nextScene); - } - - } - - /// - /// Rotates to point in specific direction based on current direction - /// - /// Local direction to point - public void Rotate (Direction direction) - { - transform.forward = direction.ToVector (transform); - } - - /// - /// Jumps in specefied direction, picks between Long Jump and Jumping up - /// - /// Direction to Jump - public void Jump (Direction direction) - { - //if there is a block infront JumpUp else LongJump - if (Block.isBlockAtPosition (CurrentBlock.position + direction.ToVector (transform) + Vector3.up, 1, ~Ignore)) - JumpUp (direction); - else - JumpLong (direction); - } - - #endregion Class Implementation - - #region Private Functions - - /// - /// Jumps up obstacle of specific height. Jumps as high as possible - /// - /// Direction of obstacle - /// max height - private void JumpUp (Direction direction, int height = 1) - { - //setting up variables - Vector3 position; // position wanted - Block hit; //output of block detection - Block moveTo = CurrentBlock; //block we'll actually move to - - //Check blocks in going up then move to the heighest walkable one - for (int i = 0; i <= height; i++) { - //next position up the tower - position = CurrentBlock.position + direction.ToVector (transform) + (Vector3.up * i); - - //if block is walkable set it to last known position - if (Block.isBlockAtPosition (position, 1, ~Ignore, out hit) && hit.isWalkable (~Ignore)) - moveTo = hit; - } - - //set current block && move - CurrentBlock = moveTo; - transform.position = CurrentBlock.VisualPosition; - } - - /// - /// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction - /// - /// Direction to Jump - /// Max distance - private void JumpLong (Direction direction, int Distance = 2) - { - //setting up variables - Vector3 position; // position wanted - Block hit; //output of block detection - Block moveTo = CurrentBlock; //block we'll actually move to - - //Check blocks in front until we hit an obstruction or went the distance - for (int i = 1; i <= Distance; i++) { - //Next position to MoveTo - position = CurrentBlock.position + (direction.ToVector (transform) * i); - - //if jump is obstructed, stop and go to last known block - if (Block.isBlockAtPosition (position + Vector3.up, 1, ~Ignore)) - break; - - - //If block at Position is walkable set it to last known position - if (Block.isBlockAtPosition (position, 1, ~Ignore, out hit) && hit.isWalkable (~Ignore)) - moveTo = hit; + } + if (other.gameObject.name == "End Portal") + { + other.GetComponent().enabled = false; + Debug.Log("You finished this level!"); + SceneManager.LoadScene(nextScene); + } + + } + + /// + /// Rotates to point in specific direction based on current direction + /// + /// Local direction to point + public void Rotate(Direction direction) + { + transform.forward = direction.ToVector(transform); + } + + /// + /// Jumps in specefied direction, picks between Long Jump and Jumping up + /// + /// Direction to Jump + public void Jump(Direction direction) + { + //if there is a block infront JumpUp else LongJump + if (Block.isBlockAtPosition(CurrentBlock.position + direction.ToVector(transform) + Vector3.up, 1, ~Ignore)) + JumpUp(direction); + else + JumpLong(direction); + } + + #endregion Class Implementation + + #region Private Functions + + /// + /// Jumps up obstacle of specific height. Jumps as high as possible + /// + /// Direction of obstacle + /// max height + private void JumpUp(Direction direction, int height = 1) + { + //setting up variables + Vector3 position; // position wanted + Block hit; //output of block detection + Block moveTo = CurrentBlock; //block we'll actually move to + + //Check blocks in going up then move to the heighest walkable one + for (int i = 0; i <= height; i++) + { + //next position up the tower + position = CurrentBlock.position + direction.ToVector(transform) + (Vector3.up * i); + + //if block is walkable set it to last known position + if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) + moveTo = hit; + } + + //set current block && move + CurrentBlock = moveTo; + transform.position = CurrentBlock.VisualPosition; + } + + /// + /// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction + /// + /// Direction to Jump + /// Max distance + private void JumpLong(Direction direction, int Distance = 2) + { + //setting up variables + Vector3 position; // position wanted + Block hit; //output of block detection + Block moveTo = CurrentBlock; //block we'll actually move to + + //Check blocks in front until we hit an obstruction or went the distance + for (int i = 1; i <= Distance; i++) + { + //Next position to MoveTo + position = CurrentBlock.position + (direction.ToVector(transform) * i); + + //if jump is obstructed, stop and go to last known block + if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) + break; + + + //If block at Position is walkable set it to last known position + if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) + moveTo = hit; //else if block down one is walkable - else if (Block.isBlockAtPosition (position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable (~Ignore)) - moveTo = hit; + else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) + moveTo = hit; - }//end for + }//end for - //Set Current Block and move - CurrentBlock = moveTo; - transform.position = CurrentBlock.VisualPosition; - } + //Set Current Block and move + CurrentBlock = moveTo; + transform.position = CurrentBlock.VisualPosition; + } - #endregion Private Functions + #endregion Private Functions } \ No newline at end of file