init
This commit is contained in:
72
Assets/Scripts/PlayerController.cs
Normal file
72
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static PlayerController instance;
|
||||
public static Transform t => instance.transform;
|
||||
public static Vector3 position=> instance.transform.position;
|
||||
public float movingSpeed = 1;
|
||||
public float speedIncremental = 0.01f;
|
||||
public float verticalSpeed = 0.5f;
|
||||
public float rotationRange = 15;
|
||||
public bool invert= true;
|
||||
|
||||
public Text txtScore;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
transform.Translate(new Vector3(movingSpeed,0), Space.World);
|
||||
|
||||
input = Mathf.Lerp(input, dif / inputRange, inputSmoothness);
|
||||
|
||||
transform.Translate(new Vector3(0,input * verticalSpeed), Space.World);
|
||||
transform.localEulerAngles = new Vector3(0,0,input * rotationRange);
|
||||
|
||||
txtScore.text = transform.position.x.ToString("n0");
|
||||
|
||||
movingSpeed += speedIncremental * Time.deltaTime;
|
||||
|
||||
}
|
||||
public float input = 0;
|
||||
public float inputSmoothness =0.1f;
|
||||
public float inputRange = 200;
|
||||
public float dif = 0;
|
||||
float startedPos=0;
|
||||
|
||||
public void OnPointerDown(BaseEventData e){
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
|
||||
startedPos = ped.position.y;
|
||||
}
|
||||
|
||||
public void OnPointerDrag(BaseEventData e){
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
|
||||
dif = (invert) ? ped.position.y-startedPos: startedPos - ped.position.y;
|
||||
}
|
||||
|
||||
public void OnPointerUp(BaseEventData e){
|
||||
dif = 0;
|
||||
startedPos = 0;
|
||||
}
|
||||
|
||||
|
||||
public void GameOver(){
|
||||
Application.LoadLevel(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user