Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var Player : GameObject;
- var Gravity:float = 2;
- var speed:float = 2;
- var anim : Animator;
- var other : enemyprefabcode;
- var combo : int = 0;
- var GUIcombo : GUIText;
- var lives : int = 3;
- var GUIlives : GUIText;
- var jumped: boolean = false;
- var jumplevel2 = false;
- var jumplevel3 = false;
- var minSwipeDistY : float;
- var minSwipeDistX : float;
- var startPos :Vector2;
- //enemy1
- var Enemyprefab : GameObject;
- function Awake(){
- GUIcombo.text = "COMBO: ";
- GUIlives.text = "LIVES: 3";
- }
- function Start () {
- anim = GetComponent(Animator);
- while (true) {
- yield WaitForSeconds (Random.Range(3, 0));
- var Enemyclone = Instantiate(Enemyprefab);
- }
- other = GameObject.FindWithTag("enemy").GetComponent("enemyprefabcode");
- }
- function Update () {
- if (lives <= 0){
- Destroy(Player);
- }
- Player.transform.position.x = -4.325;
- if (jumped == false){
- anim.SetFloat("hf",0.0);
- }
- if(Input.GetButtonDown("Fire1") && jumped==false){
- jumpup();
- jumped = true;
- }
- if(jumped==true){
- anim.SetFloat("hf",1);
- }
- if (Input.touchCount > 0)
- {
- var touch : Touch = Input.touches[0];
- switch (touch.phase)
- {
- case TouchPhase.Began:
- startPos = touch.position;
- break;
- case TouchPhase.Ended:
- var swipeDistVertical : float;
- swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
- if (swipeDistVertical > minSwipeDistY)
- {
- var swipeValue : float;
- swipeValue = Mathf.Sign(touch.position.y - startPos.y);
- if (swipeValue > 0)//up
- {
- glide();
- //Swipe.text = "Up Swipe";
- }
- else if (swipeValue < 0)//down
- {
- slam();
- //Swipe.text = "Down Swipe";
- }
- }
- var swipeDistHorizontal : float;
- swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
- if (swipeDistHorizontal > minSwipeDistX)
- {
- swipeValue = Mathf.Sign(touch.position.x - startPos.x);
- if (swipeValue > 0)//right
- {
- //MoveRight ();
- //Swipe.text = "Right Swipe";
- }
- else if (swipeValue < 0)//left
- {
- //MoveLeft ();
- //Swipe.text = "Left Swipe";
- }
- }
- break;
- }
- }
- }
- function OnCollisionEnter2D(coll: Collision2D) {
- if(coll.gameObject.CompareTag("ground")){
- anim.SetFloat("hf",0.0);
- jumped=false;
- combo = 0;
- GUIcombo.text = "COMBO: " + combo;
- }
- if(coll.gameObject.CompareTag("enemy") && jumped==true){
- other.isdying=true;
- //Destroy(coll.gameObject);
- jumpup();
- jumped=true;
- combo += 1;
- GUIcombo.text = "COMBO: " + combo;
- }
- if(coll.gameObject.CompareTag("enemy") && jumped==false){
- lives -=1;
- GUIlives.text = "LIVES: " + lives;
- }
- }
- function slam(){
- Player.rigidbody2D.AddForce(new Vector2(0,-3000), ForceMode2D.Force);
- }
- function glide(){
- Player.rigidbody2D.AddForce(Vector2(0,600), ForceMode2D.Force);
- }
- function jumpup(){
- Player.transform.Translate(Vector3(Input.GetAxis("Vertical") * speed * Time.deltaTime, 0, 0));
- Player.rigidbody2D.velocity = Vector2(0,10);
- if(jumplevel2==true){
- Player.rigidbody2D.velocity = Vector2(0,13);
- }
- if(jumplevel3==true){
- Player.rigidbody2D.velocity = Vector2(0,16);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement