player movement kesz
This commit is contained in:
@@ -7,14 +7,18 @@ public class CameraController : MonoBehaviour
|
||||
public GameObject player;
|
||||
public Camera camera;
|
||||
private Vector3 offset;
|
||||
public float xPostion = 0;
|
||||
|
||||
void Start(){
|
||||
offset.x = xPostion;
|
||||
offset.y = camera.transform.position.y - player.transform.position.y;
|
||||
offset.z = camera.transform.position.z - player.transform.position.z;
|
||||
|
||||
void Start()
|
||||
{
|
||||
offset = camera.transform.position - player.transform.position;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
camera.transform.position = player.transform.position + offset;
|
||||
if(player.transform.position.x != 3 || player.transform.position.x != -3)
|
||||
camera.transform.position = player.transform.position + offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@ using UnityEngine;
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public Rigidbody rb;
|
||||
private CameraController cc;
|
||||
//public float moveSpeed = 5f;
|
||||
public float jumpforce = 5f;
|
||||
public float sideMovement = 3f;
|
||||
private Vector3 direction;
|
||||
private float horizontal, vertical, isJumping;
|
||||
private bool isOnGround;
|
||||
@@ -16,26 +18,16 @@ public class PlayerController : MonoBehaviour
|
||||
private Vector2 endTouchPosition;
|
||||
|
||||
private void Awake() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
cc = FindObjectOfType<CameraController>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
/*horizontal = Input.GetAxis("Horizontal");
|
||||
vertical = Input.GetAxis("Vertical");
|
||||
isJumping = Input.GetAxis("Jump");*/
|
||||
|
||||
void Update(){
|
||||
//jumping
|
||||
/*if (isJumping > 0 && isOnGround) {
|
||||
rb.AddForce(new Vector3(horizontal, jumpforce, vertical));
|
||||
isOnGround = false;
|
||||
}*/
|
||||
|
||||
/*direction = new Vector3(horizontal, 0,vertical);
|
||||
rb.AddForce(direction * moveSpeed * Time.deltaTime);*/
|
||||
|
||||
|
||||
|
||||
//new character controller with swipe lane changing
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
|
||||
startTouchPosition = Input.GetTouch(0).position;
|
||||
@@ -61,10 +53,14 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
|
||||
private void goLeft(){
|
||||
rb.transform.position = new Vector3(rb.transform.position.x + 5, rb.transform.position.y, rb.transform.position.z);
|
||||
if(rb.transform.position.x == 3) 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);
|
||||
}
|
||||
|
||||
private void goRight(){
|
||||
rb.transform.position = new Vector3(rb.transform.position.x - 5, rb.transform.position.y, rb.transform.position.z);
|
||||
if(rb.transform.position.x == -3) 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user