commit1e4ffae4f6Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:23:47 2023 +0200 proba athozas veszelyes commit0297a2cb78Merge:604088e31b9214Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:09:48 2023 +0200 Merge branch 'master' of https://github.com/playmaker1210/PuzzleColorBall commit31b9214f35Merge:184d2e889976bbAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:42:34 2023 +0200 Merge https://github.com/playmaker1210/PuzzleColorBall commit184d2e84daAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:41:59 2023 +0200 server mukodik commit89976bbcf8Author: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:28 2023 +0200 Update README.md commit250cc0ffeeAuthor: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:01 2023 +0200 Create README.md commit2f0ae77e35Author: playmaker1210 <hatvanitamas09@gmail.com> Date: Thu May 4 12:56:56 2023 +0200 update commitb94c80b293Author: Playmaker1210 <hatvanitamas09@gmail.com> Date: Tue May 2 13:46:38 2023 +0200 coin db working commit25d792e0fdAuthor: playmaker1210 <hatvanitamas09@gmail.com> Date: Sat Apr 29 17:07:23 2023 +0200 update
135 lines
5.0 KiB
C#
135 lines
5.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
public Rigidbody rb; //jatekos teste
|
|
private CameraController cc;
|
|
private IsGrounded isGrounded;
|
|
|
|
public float jumpforce = 5f; //mekkorat tudjon ugorni
|
|
private float sideMovement = 3f; //oldalra mennyit mozogjon
|
|
private Vector3 direction; //jatkos pozicio
|
|
private bool isJumping; //levegobe van e
|
|
public float holdTime = 0.3f; //meddig kell nyomni egy érintéshez
|
|
private bool isTapped = false; //kattintas erzekeles
|
|
private float timeSinceLastTap = 0f; //mennyi ido telt el a legutolso erintes ota
|
|
private Vector2 startTouchPosition; //erintes kezdo pozicio
|
|
private Vector2 endTouchPosition; //erintes vegpozicio
|
|
|
|
public ControlType activeControllType; //ezt kell atallitani hogy swipe-os vagy button-os legyen a mozgas
|
|
|
|
public Button leftButton;
|
|
public Button jumpButton;
|
|
public Button rightButton;
|
|
|
|
public enum ControlType
|
|
{
|
|
Swipe,
|
|
Button
|
|
}
|
|
|
|
private void Awake() {
|
|
cc = FindObjectOfType<CameraController>(); //kamera vezerlo referencia
|
|
isGrounded = FindObjectOfType<IsGrounded>();
|
|
|
|
//activeControllType = ControlType.Button;
|
|
}
|
|
|
|
public void setControllType(ControlType controlltype){
|
|
activeControllType = controlltype;
|
|
}
|
|
|
|
private void Update(){
|
|
|
|
if(activeControllType == ControlType.Swipe){
|
|
leftButton.gameObject.SetActive(false);
|
|
jumpButton.gameObject.SetActive(false);
|
|
rightButton.gameObject.SetActive(false);
|
|
|
|
//jumping
|
|
if(Input.touchCount > 0){
|
|
Touch touch = Input.GetTouch(0); //elso erintes lekerese
|
|
|
|
if(touch.phase == TouchPhase.Began){ //ha az erintes elkezdotott
|
|
isTapped = true;
|
|
timeSinceLastTap = Time.time;
|
|
}
|
|
|
|
if(touch.phase == TouchPhase.Ended){ //ha az erintes befejezodott
|
|
isTapped = false;
|
|
timeSinceLastTap = 0f;
|
|
}
|
|
|
|
if(isTapped && isGrounded.isGrounded){
|
|
if(Time.time - timeSinceLastTap >= holdTime){ //ha nyomva tartotta a beallitott ideig
|
|
Debug.Log("Long tapped");
|
|
jump();
|
|
isTapped = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
//new character controller with swipe lane changing
|
|
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ //elso erintes elkezdodott
|
|
startTouchPosition = Input.GetTouch(0).position;
|
|
}
|
|
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){ //elso erintes befejezodott
|
|
endTouchPosition = Input.GetTouch(0).position;
|
|
|
|
if(endTouchPosition.x < startTouchPosition.x){ //balra huzott
|
|
//left
|
|
goLeft();
|
|
|
|
}else if(endTouchPosition.x > startTouchPosition.x){ //jobbra huzott
|
|
//right
|
|
goRight();
|
|
}
|
|
}
|
|
}else if(activeControllType == ControlType.Button){
|
|
//jumpforce = 100;
|
|
/*leftButton.onClick.AddListener(goRight);
|
|
jumpButton.onClick.AddListener(jump);
|
|
rightButton.onClick.AddListener(goLeft);*/
|
|
}
|
|
}
|
|
|
|
public void goLeft(){ //helyezze at a jatekos objektumot a balra levo savba
|
|
Debug.Log("kattintva bal");
|
|
if(rb.transform.position.x <= -2.5f) return; //ne tudjon kimenni a savbol
|
|
//cc.xPostion = -3; //kamera xPozicioja
|
|
//rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
|
|
|
|
if(rb.transform.position.x >= 2.5f){
|
|
rb.transform.position = new Vector3(0, rb.transform.position.y, rb.transform.position.z);
|
|
}else if(rb.transform.position.x >= -2.5f){
|
|
rb.transform.position = new Vector3(-3f, rb.transform.position.y, rb.transform.position.z);
|
|
}
|
|
}
|
|
|
|
public void goRight(){ //helyezze at a jatekos objektumot a jobbra levo savba
|
|
Debug.Log("kattintva jobb");
|
|
if(rb.transform.position.x >= 2.5f) return; //ne tudjon kimenni a savbol
|
|
//cc.xPostion = 3; //kamera xPozicioja
|
|
//rb.transform.position = new Vector3(rb.transform.position.x + sideMovement, rb.transform.position.y, rb.transform.position.z);
|
|
|
|
if(rb.transform.position.x <= -2.5f){
|
|
rb.transform.position = new Vector3(0, rb.transform.position.y, rb.transform.position.z);
|
|
}else if(rb.transform.position.x >= -2.5f){
|
|
rb.transform.position = new Vector3(3f, rb.transform.position.y, rb.transform.position.z);
|
|
}
|
|
}
|
|
|
|
public void jump(){
|
|
if(isGrounded.isGrounded){
|
|
rb.AddForce(new Vector3(0, jumpforce, 0)); //ugras
|
|
isGrounded.isGrounded = false;
|
|
}
|
|
|
|
Debug.Log("jumped");
|
|
}
|
|
|
|
|
|
} |