player is jumping
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b4dc5f685f8edc4bbba6fb0c8ea39ba
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8851c5995be5f704babebf752d60b4e2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88c6da05db186cb44a4453fd624b31b2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.56158954, g: 0.7218083, b: 0.8178571, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.5615895, g: 0.72180885, b: 0.81785697, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -288,8 +288,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
rb: {fileID: 7917514869596290073}
|
||||
jumpforce: 350
|
||||
sideMovement: 3
|
||||
isJumping: 0
|
||||
holdTime: 0.15
|
||||
--- !u!1001 &1265567512
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9743,7 +9742,7 @@ Rigidbody:
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 112
|
||||
m_CollisionDetection: 2
|
||||
m_CollisionDetection: 0
|
||||
--- !u!136 &7917514869596290074
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -8,12 +8,18 @@ public class PlayerController : MonoBehaviour
|
||||
private CameraController cc;
|
||||
//public float moveSpeed = 5f;
|
||||
public float jumpforce = 5f;
|
||||
public float sideMovement = 3f;
|
||||
private float sideMovement = 3f;
|
||||
private Vector3 direction;
|
||||
private float horizontal, vertical;
|
||||
public bool isJumping;
|
||||
private bool isJumping;
|
||||
private bool isOnGround;
|
||||
|
||||
|
||||
//
|
||||
public float holdTime = 0.3f;
|
||||
private bool isTapped = false;
|
||||
private float timeSinceLastTap = 0f;
|
||||
|
||||
//swipe movement
|
||||
private Vector2 startTouchPosition;
|
||||
private Vector2 endTouchPosition;
|
||||
@@ -22,17 +28,28 @@ public class PlayerController : MonoBehaviour
|
||||
cc = FindObjectOfType<CameraController>();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
private void Update(){
|
||||
//jumping
|
||||
if (Input.touchCount > 0) {
|
||||
var startPosition = Input.GetTouch(0).position;
|
||||
if(Input.GetTouch(0).phase == TouchPhase.Ended && !isJumping && Input.GetTouch(0).position == startPosition){
|
||||
rb.AddForce(new Vector3(0, jumpforce, 0));
|
||||
isJumping = true;
|
||||
}else if(Input.GetTouch(0).phase == TouchPhase.Ended ){
|
||||
isJumping = false;
|
||||
if(Input.touchCount > 0){
|
||||
Touch touch = Input.GetTouch(0);
|
||||
|
||||
if(touch.phase == TouchPhase.Began){
|
||||
isTapped = true;
|
||||
timeSinceLastTap = Time.time;
|
||||
}
|
||||
|
||||
if(touch.phase == TouchPhase.Ended){
|
||||
isTapped = false;
|
||||
timeSinceLastTap = 0f;
|
||||
}
|
||||
|
||||
if(isTapped && rb.transform.position.y <= 0.16f){
|
||||
if(Time.time - timeSinceLastTap >= holdTime){
|
||||
Debug.Log("Long tapped");
|
||||
rb.AddForce(new Vector3(0, jumpforce, 0));
|
||||
isTapped = false;
|
||||
}
|
||||
}
|
||||
//isOnGround = false;
|
||||
}
|
||||
|
||||
//new character controller with swipe lane changing
|
||||
@@ -42,7 +59,7 @@ public class PlayerController : MonoBehaviour
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){
|
||||
endTouchPosition = Input.GetTouch(0).position;
|
||||
|
||||
if(endTouchPosition.x + 200< startTouchPosition.x){
|
||||
if(endTouchPosition.x < startTouchPosition.x){
|
||||
//left
|
||||
goLeft();
|
||||
|
||||
@@ -53,21 +70,17 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/*private void OnCollisionEnter(Collision collision) {
|
||||
if (collision.collider.CompareTag("Ground")) {
|
||||
isOnGround = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
private void goLeft(){
|
||||
if(rb.transform.position.x == 3) return; //ne tudjon kimenni a savbol
|
||||
if(rb.transform.position.x >= 2.5f) return; //ne tudjon kimenni a savbol
|
||||
cc.xPostion = -3;
|
||||
rb.transform.position = new Vector3(rb.transform.position.x + sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
//rb.transform.position = new Vector3(rb.transform.position.x + sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
rb.AddForce(new Vector3(300f, 0, 0));
|
||||
}
|
||||
|
||||
private void goRight(){
|
||||
if(rb.transform.position.x == -3) return; //ne tudjon kimenni a savbol
|
||||
if(rb.transform.position.x <= -2.5f) return; //ne tudjon kimenni a savbol
|
||||
cc.xPostion = 3;
|
||||
rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
//rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
rb.AddForce(new Vector3(-300f, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user