|
@ -7,11 +7,11 @@ using Networking.Server; |
|
|
|
|
|
|
|
|
public class Character : MonoBehaviour |
|
|
public class Character : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
public enum Animation {Walk,Run,Jump,Slide} |
|
|
|
|
|
|
|
|
public enum Animation { Walk, Run, Jump, Slide } |
|
|
|
|
|
|
|
|
public string nextScene; |
|
|
public string nextScene; |
|
|
Animator characterAnimator; |
|
|
Animator characterAnimator; |
|
|
public bool isTuteLevel = false; |
|
|
|
|
|
|
|
|
public bool isTuteLevel = false; |
|
|
|
|
|
|
|
|
public bool inWater = false; //Am I in the water?
|
|
|
public bool inWater = false; //Am I in the water?
|
|
|
public bool inPit = false; //Did I fall into a pit?
|
|
|
public bool inPit = false; //Did I fall into a pit?
|
|
@ -26,7 +26,7 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
[SerializeField] |
|
|
[Tooltip("Layers to ignore when checking for blocks")] |
|
|
[Tooltip("Layers to ignore when checking for blocks")] |
|
|
private LayerMask Ignore; |
|
|
|
|
|
|
|
|
public LayerMask Ignore; |
|
|
|
|
|
|
|
|
[Tooltip("Current Inventory of the player")] |
|
|
[Tooltip("Current Inventory of the player")] |
|
|
public Inventory Inventory; |
|
|
public Inventory Inventory; |
|
@ -87,28 +87,31 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
|
public void DisplayBlock(LogicBlock block) |
|
|
public void DisplayBlock(LogicBlock block) |
|
|
{ |
|
|
{ |
|
|
if(isTuteLevel == false){ |
|
|
|
|
|
if (BlockTitlePrefab == null) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
TMPro.TextMeshPro temp = Instantiate(BlockTitlePrefab.gameObject).GetComponent<TMPro.TextMeshPro>(); |
|
|
|
|
|
temp.text = block.DisplayName; |
|
|
|
|
|
|
|
|
if (isTuteLevel == false) |
|
|
|
|
|
{ |
|
|
|
|
|
if (BlockTitlePrefab == null) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
TMPro.TextMeshPro temp = Instantiate(BlockTitlePrefab.gameObject).GetComponent<TMPro.TextMeshPro>(); |
|
|
|
|
|
temp.text = block.DisplayName; |
|
|
temp.color = ClientLink.Color; |
|
|
temp.color = ClientLink.Color; |
|
|
|
|
|
|
|
|
temp.transform.position = transform.position + (Vector3.one * 0.25f); |
|
|
|
|
|
temp.transform.rotation = Quaternion.LookRotation(temp.transform.position - Camera.main.transform.position); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
temp.transform.position = transform.position + (Vector3.one * 0.25f); |
|
|
|
|
|
temp.transform.rotation = Quaternion.LookRotation(temp.transform.position - Camera.main.transform.position); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Vector3 yValue(float time, float heightMultiplier) |
|
|
|
|
|
|
|
|
public float yValue(float time, float heightMultiplier) |
|
|
{ |
|
|
{ |
|
|
float y = Mathf.Sin((Mathf.PI * time)) * heightMultiplier; |
|
|
float y = Mathf.Sin((Mathf.PI * time)) * heightMultiplier; |
|
|
return new Vector3(0, y, 0); |
|
|
|
|
|
|
|
|
return y; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerator MoveToBlock(Block target, Animation animation, float time) |
|
|
public IEnumerator MoveToBlock(Block target, Animation animation, float time) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
System.Func<float, float> yFunction = null; |
|
|
|
|
|
|
|
|
switch (animation) |
|
|
switch (animation) |
|
|
{ |
|
|
{ |
|
|
case Animation.Walk: |
|
|
case Animation.Walk: |
|
@ -119,20 +122,30 @@ public class Character : MonoBehaviour |
|
|
break; |
|
|
break; |
|
|
case Animation.Jump: |
|
|
case Animation.Jump: |
|
|
characterAnimator.SetTrigger("Jump"); |
|
|
characterAnimator.SetTrigger("Jump"); |
|
|
|
|
|
yFunction = (t) => yValue(t, 1.0f); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
yield return StartCoroutine(LerpToBlock(target, time, yFunction)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield return null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (animation) |
|
|
|
|
|
{ |
|
|
|
|
|
case Animation.Walk: |
|
|
|
|
|
characterAnimator.SetBool("isWalking", false); |
|
|
|
|
|
break; |
|
|
|
|
|
case Animation.Run: |
|
|
|
|
|
characterAnimator.SetBool("isRunning", false); |
|
|
|
|
|
break; |
|
|
|
|
|
case Animation.Jump: |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerator LerpToBlock(Block target,float time, System.Func<float,float> heightOffset) |
|
|
|
|
|
|
|
|
public IEnumerator LerpToBlock(Block target, float time, System.Func<float, float> heightOffset = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
Vector3 _startPos = transform.position; |
|
@ -141,7 +154,7 @@ public class Character : MonoBehaviour |
|
|
Vector3 _newPos; |
|
|
Vector3 _newPos; |
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
while(elapsedTime/time < 1) |
|
|
|
|
|
|
|
|
while (elapsedTime / time < 1) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
_newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time)); |
|
|
_newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time)); |
|
@ -155,7 +168,8 @@ public class Character : MonoBehaviour |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_newPos = _endPos; |
|
|
_newPos = _endPos; |
|
|
_newPos.y += heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
_newPos.y += heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
transform.position = _newPos; |
|
|
transform.position = _newPos; |
|
|
} |
|
|
} |
|
@ -171,7 +185,7 @@ public class Character : MonoBehaviour |
|
|
while (elapsedTime < time) |
|
|
while (elapsedTime < time) |
|
|
{ |
|
|
{ |
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
transform.position += yValue((elapsedTime / time), heightMax); |
|
|
|
|
|
|
|
|
//transform.position += yValue((elapsedTime / time), heightMax);
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
@ -297,7 +311,7 @@ public class Character : MonoBehaviour |
|
|
while (elapsedTime < time) |
|
|
while (elapsedTime < time) |
|
|
{ |
|
|
{ |
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
transform.position += yValue((elapsedTime / time), heightMax); |
|
|
|
|
|
|
|
|
//transform.position += yValue((elapsedTime / time), heightMax);
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
@ -366,7 +380,7 @@ public class Character : MonoBehaviour |
|
|
_currentBlock = moveTo; |
|
|
_currentBlock = moveTo; |
|
|
StartCoroutine(MoveConveyorForwardCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
StartCoroutine(MoveConveyorForwardCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
public void conveyorMoveBackward(Direction direction, float speed) |
|
|
public void conveyorMoveBackward(Direction direction, float speed) |
|
|
{ |
|
|
{ |
|
@ -499,9 +513,9 @@ public class Character : MonoBehaviour |
|
|
this.transform.position = currentBlock.VisualPosition; |
|
|
this.transform.position = currentBlock.VisualPosition; |
|
|
this.inPit = false; |
|
|
this.inPit = false; |
|
|
this._currentBlock = currentBlock; |
|
|
this._currentBlock = currentBlock; |
|
|
Debug.Log("Moved " + this.name + " to " |
|
|
|
|
|
+ this.transform.position.x + ", " |
|
|
|
|
|
+ this.transform.position.y + ", " |
|
|
|
|
|
|
|
|
Debug.Log("Moved " + this.name + " to " |
|
|
|
|
|
+ this.transform.position.x + ", " |
|
|
|
|
|
+ this.transform.position.y + ", " |
|
|
+ this.transform.position.z + ", " |
|
|
+ this.transform.position.z + ", " |
|
|
+ " inPit = " + inPit); |
|
|
+ " inPit = " + inPit); |
|
|
} |
|
|
} |
|
|