|
@ -8,7 +8,6 @@ public class Character : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
public string nextScene; |
|
|
public string nextScene; |
|
|
Animator characterAnimator; |
|
|
Animator characterAnimator; |
|
|
bool isWalking = false; |
|
|
|
|
|
|
|
|
|
|
|
#region Inspector Fields
|
|
|
#region Inspector Fields
|
|
|
|
|
|
|
|
@ -40,14 +39,13 @@ public class Character : MonoBehaviour |
|
|
Block.isBlockAtPosition(transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock); |
|
|
Block.isBlockAtPosition(transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock); |
|
|
|
|
|
|
|
|
//move to starting block
|
|
|
//move to starting block
|
|
|
transform.position = CurrentBlock.VisualPosition; |
|
|
|
|
|
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
|
|
|
|
|
//get character string from player replace from "Bear"
|
|
|
//get character string from player replace from "Bear"
|
|
|
GameObject prefab = Resources.Load("Bear") as GameObject; |
|
|
GameObject prefab = Resources.Load("Bear") as GameObject; |
|
|
GameObject Bear = Instantiate(prefab, this.gameObject.transform); |
|
|
GameObject Bear = Instantiate(prefab, this.gameObject.transform); |
|
|
|
|
|
|
|
|
characterAnimator = GetComponentInChildren<Animator>(); |
|
|
characterAnimator = GetComponentInChildren<Animator>(); |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion Unity Functions
|
|
|
#endregion Unity Functions
|
|
@ -75,12 +73,10 @@ public class Character : MonoBehaviour |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
transform.position = Target.VisualPosition; |
|
|
transform.position = Target.VisualPosition; |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
{ |
|
|
{ |
|
|
isWalking = true; |
|
|
|
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
Vector3 startPosition = Current.position; |
|
|
Vector3 startPosition = Current.position; |
|
|
time *= 0.8f; |
|
|
time *= 0.8f; |
|
@ -94,7 +90,6 @@ public class Character : MonoBehaviour |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
transform.position = Target.VisualPosition; |
|
|
transform.position = Target.VisualPosition; |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IEnumerator MoveDownCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
IEnumerator MoveDownCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
@ -111,7 +106,6 @@ public class Character : MonoBehaviour |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
transform.position = Target.VisualPosition; |
|
|
transform.position = Target.VisualPosition; |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax) |
|
|
IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax) |
|
@ -129,7 +123,6 @@ public class Character : MonoBehaviour |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
transform.forward = endDirection; |
|
|
transform.forward = endDirection; |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,20 +147,16 @@ public class Character : MonoBehaviour |
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)){ |
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)){ |
|
|
moveTo = hit; |
|
|
moveTo = hit; |
|
|
CurrentBlock = moveTo; |
|
|
CurrentBlock = moveTo; |
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.3f)); } |
|
|
//else if block down one is walkable
|
|
|
//else if block down one is walkable
|
|
|
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)){ |
|
|
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)){ |
|
|
moveTo = hit; |
|
|
moveTo = hit; |
|
|
CurrentBlock = moveTo; |
|
|
CurrentBlock = moveTo; |
|
|
StartCoroutine(MoveDownCoroutine(CurrentBlock, transform, speed, 0.3f)); |
|
|
StartCoroutine(MoveDownCoroutine(CurrentBlock, transform, speed, 0.3f)); |
|
|
characterAnimator.Play("Idle"); |
|
|
|
|
|
} |
|
|
} |
|
|
//set current block && move
|
|
|
//set current block && move
|
|
|
//CurrentBlock = moveTo;
|
|
|
//CurrentBlock = moveTo;
|
|
|
//StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.3f));
|
|
|
//StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.3f));
|
|
|
//characterAnimator.Play("Idle");
|
|
|
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|