/
crypt
/
SnowBallRefactoring
Обзор
Документация
Войти
/
crypt
/
SnowBallRefactoring
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/endlesGame.cs
377 строк
8 KB
crypt
Мой первый проект. Старт рефакторинга.
21 июл 2026, 18:23
21 июл 2026, 18:23
bef234c
Код
Авторство
О чём код?
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class endlesGame : MonoBehaviour { public GameObject died_ball; public GameObject pause_button; public GameObject panel_pause; /* public AudioClip SoundCrash; public AudioClip SoundHeart; public AudioClip SoundCoin; */ public AudioClip SoundWood; public GameObject BoomTree; public GameObject BoomStone; AudioSource AS; // public GameObject winder; public static bool ismoved; public static bool crash; public static Transform tr; // bool wind = false; float moveHorizontal; Rigidbody2D RbBall; // GameObject ball; public static Transform TrBall; public int power; public float speed; public static bool coinSound=false; public static bool heartSound=false; public static bool crashTree=false; public static bool crashStone=false; int speedScale; public static bool isMain=false; public static int countColission=5; // ParticleSystem ps; public static float score; void Start() { AS = GetComponent<AudioSource>(); ismoved = true; RbBall = GetComponent<Rigidbody2D>(); TrBall = GetComponent<Transform>(); power = 80; speed = 20; score = 0; speedScale = (int)TrBall.localScale.x; countColission = 5; tr = GetComponent<Transform>(); } void Update() { if (Mathf.Round(TrBall.localScale.x) == speedScale) { speed++; speedScale++; } if (start_game_push.start_game_bool && ismoved) { score +=Time.deltaTime* TrBall.localScale.x*2; if (score < 0) score = 0; speed += Time.deltaTime/3; RbBall.mass += 0.001f; TrBall.localScale += new Vector3(0.003f, 0.003f,0f); } if (Application.platform == RuntimePlatform.Android) { moveHorizontal = Input.acceleration.x; } else { moveHorizontal = Input.GetAxis("Horizontal"); } if (start_game_push.start_game_bool && !crash && ismoved) { transform.position = new Vector3(transform.position.x + moveHorizontal * Time.deltaTime * speed * 2f, transform.position.y, transform.position.z); transform.Translate(Vector3.down * Time.deltaTime * speed); } /* if (wind) { transform.position = new Vector3(transform.position.x + Time.deltaTime * -speed, transform.position.y, transform.position.z); winder.SetActive(true); } else winder.SetActive(false); */ if (countColission <=0) { died_ball.SetActive(true); ismoved = false; } // RbBall.AddForce(transform.right*moveHorizontal*-power*RbBall.mass); if (transform.position.x < -32f) transform.position = new Vector3(-32f, transform.position.y, transform.position.z); if (transform.position.x > 32f) transform.position = new Vector3(32f, transform.position.y, transform.position.z); } void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "elka2") { // SpecialEffect.Instance.Explosion(col.transform.position); Instantiate(BoomTree, col.transform.position, Quaternion.identity); Destroy(GameObject.FindGameObjectWithTag("BoomTree"), 3); Destroy(col.gameObject); countColission--; RbBall.mass -= RbBall.mass / 5; score -= 30; TrBall.localScale = TrBall.localScale / 1.5f; if (PlayerPrefs.GetInt("isSound") == 1) crashTree = true; /* AS.clip = SoundCrash; if (PlayerPrefs.GetInt("isSound") == 1) AS.Play();*/ } if (col.gameObject.tag == "stone") { Instantiate(BoomStone, col.transform.position, Quaternion.identity); Destroy(GameObject.FindGameObjectWithTag("BoomStone"), 3); //SpecialEffect.Instance.Explosion(col.transform.position); Destroy(col.gameObject); countColission--; RbBall.mass -= RbBall.mass / 5; score -= 20; TrBall.localScale = TrBall.localScale / 1.3f; if (PlayerPrefs.GetInt("isSound") == 1) crashStone = true; /* AS.clip = SoundCrash; if (PlayerPrefs.GetInt("isSound") == 1) AS.Play();*/ } if (col.gameObject.tag == "finish") { start_game_push.start_game_bool = false; SceneManager.LoadScene("Result_level"); Destroy(gameObject); // Application.LoadLevel(); } if (col.gameObject.tag == "heart") { Destroy(col.gameObject); score += 50; countColission++; if (PlayerPrefs.GetInt("isSound") == 1) heartSound = true; /* AS.clip = SoundHeart; if (PlayerPrefs.GetInt("isSound") == 1) AS.Play();*/ } if (col.gameObject.tag == "coin") { Destroy(col.gameObject); score += 500; if (PlayerPrefs.GetInt("isSound") == 1) coinSound = true; /* AS.clip = SoundCoin; if (PlayerPrefs.GetInt("isSound") == 1) AS.Play(); */ } } public void to_select_level() { died_ball.SetActive(false); start_game_push.start_game_bool = false; // Application.LoadLevel(1); SceneManager.LoadSceneAsync(1); } public void creak() { if (PlayerPrefs.GetInt("isSound") == 1) { AS.clip = SoundWood; AS.Play(); } } public void to_top() { died_ball.SetActive(false); start_game_push.start_game_bool = false; isMain = false; SceneManager.LoadScene("Top"); } public void restart() { start_game_push.start_game_bool = false; Level_pick.helper_level = 11; Debug.Log( Level_pick.helper_level); died_ball.SetActive(false); switch (Level_pick.helper_level) { case 1: // Application.LoadLevel("Level_1"); SceneManager.LoadSceneAsync("Level_1"); break; case 2: SceneManager.LoadSceneAsync("Level_2"); break; case 3: SceneManager.LoadSceneAsync("Level_3"); break; case 4: SceneManager.LoadSceneAsync("Level_4"); break; case 5: SceneManager.LoadSceneAsync("Level_5"); break; case 6: SceneManager.LoadSceneAsync("Level_6"); break; case 7: SceneManager.LoadSceneAsync("Level_7"); break; case 8: SceneManager.LoadSceneAsync("Level_8"); break; case 9: SceneManager.LoadSceneAsync("Level_9"); break; case 10: SceneManager.LoadSceneAsync("Level_10"); break; case 11: SceneManager.LoadSceneAsync("bonus"); Debug.Log("bonus") ; break; } } public void unpause_game() { ismoved = true; pause_button.SetActive(true); panel_pause.SetActive(false); } public void pause_game() { ismoved = false; //ps.Pause(); pause_button.SetActive(false); panel_pause.SetActive(true); } public void OnGUI() { if (Input.GetKeyUp(KeyCode.Escape)) { ismoved = false; // ps.Pause(); pause_button.SetActive(false); panel_pause.SetActive(true); } } }