Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class ball : MonoBehaviour
- {
- Rigidbody rb;
- public bool jump, bjump, ss;
- float z, startTouch, x;
- public GameObject next;
- // Use this for initialization
- void Start()
- {
- Application.targetFrameRate = 60;
- rb = GetComponent<Rigidbody>();
- jump = false;
- ss = true;
- bjump = false;
- rb.velocity = new Vector3(0, -4f, 0);
- }
- public void Update()
- {
- if (transform.position.y <= -.75f)
- {
- ss = false;
- }
- Touch();
- if (z + 4.5f <= transform.position.z)
- {
- if (bjump == true)
- {
- if (z + 19.5f <= transform.position.z)
- {
- transform.position = new Vector3(transform.position.x, transform.position.y, z + 20f);
- rb.velocity = new Vector3(0, -4f, 0);
- bjump = false;
- }
- }
- if (jump == true)
- {
- transform.position = new Vector3(transform.position.x, transform.position.y, z + 5f);
- rb.velocity = new Vector3(0, -4f, 0);
- jump = false;
- }
- }
- Vector3 tmpPos = transform.position;
- tmpPos.x = Mathf.Clamp(tmpPos.x, -2.25f, 2.25f);
- transform.position = tmpPos;
- }
- public void OnCollisionEnter(Collision collisionInfo)
- {
- if (collisionInfo.collider.tag == "Untagged")
- {
- transform.position = new Vector3(transform.position.x, transform.position.y, next.transform.position.z);
- next.transform.position = new Vector3 (0, -1.4f, next.transform.position.z + 5f);
- rb.velocity = new Vector3(0, 10f, 9.5f);
- z = transform.position.z;
- jump = true;
- bjump = false;
- }
- if (collisionInfo.collider.tag == "BigJump")
- {
- transform.position = new Vector3(transform.position.x, transform.position.y, next.transform.position.z);
- next.transform.position = new Vector3(0, -1.4f, next.transform.position.z + 20f);
- rb.velocity = new Vector3(0, 15f, 25.5f);
- z = transform.position.z;
- bjump = true;
- jump = false;
- }
- if (collisionInfo.collider.tag == "Finish")
- {
- ss = false;
- Invoke("reset" , 1f);
- }
- if (collisionInfo.collider.tag == "Respawn")
- {
- //death
- Invoke("reset", 1f);
- }
- }
- public void reset()
- {
- SceneManager.LoadScene(0);
- }
- public void Touch()
- {
- if (ss == true)
- {
- if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
- {
- int num = Input.GetTouch(0).fingerId;
- startTouch = Input.GetTouch(0).position.x;
- }
- if (Input.touchCount > 0 && Input.GetTouch(0).fingerId == 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
- {
- x = Input.GetTouch(0).position.x - startTouch;
- if (x > 0)
- {
- float w = Screen.width;
- float a = x / w * (400);
- rb.MovePosition(transform.position + transform.right * Time.deltaTime * a);
- }
- else if (x < 0)
- {
- float w = Screen.width;
- float a = x / w * (400);
- rb.MovePosition(transform.position + transform.right * Time.deltaTime * a);
- }
- }
- if (Input.touchCount > 0)
- {
- startTouch = Input.GetTouch(0).position.x;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement