// Use this for initialization void Start() { try { text = GameObject.Find("Text").GetComponent <Text>(); animator = Unitychan.GetComponent <Animator>(); rb = Unitychan.GetComponent <Rigidbody>(); Enemy0_scripts = Enemy0.GetComponent <Animation1>(); Enemy1_scripts = Enemy1.GetComponent <Animation5>(); Light_scripts = LightManager.GetComponent <Animation2>(); Sword_scripts = SwordManager.GetComponent <Animation3>(); Player_scripts = Player.GetComponent <Animation4>(); Camera_scripts = Camera.GetComponent <Animation4>(); UnityChan_scripts = Unitychan.GetComponent <Opening_UnityChan>(); EnemyMaster_scripts = EnemyMaster.GetComponent <EnemyGenerator>(); opening = true; countdown = false; playing = false; gameover = false; clear = false; } catch (Exception e) { Debug.Log("exception"); } }
// Update is called once per frame void Update() { Win(); if (player1) { if (Input.GetAxis("Horizontal_P1") > 0) { gameObject.transform.position += transform.right * Time.deltaTime * speed; if (facingright != true) { //SR.flipX = false; transform.localScale += new Vector3(+flipNumber, 0, 0); facingright = true; } } if (Input.GetAxis("Horizontal_P1") < 0) { gameObject.transform.position += -transform.right * Time.deltaTime * speed; if (facingright == true) { //SR.flipX = true; transform.localScale += new Vector3(-flipNumber, 0, 0); facingright = false; } } if (Input.GetAxis("Jump_P1") > 0 && GetComponent <Rigidbody2D> ().velocity.y == 0) { GetComponent <Rigidbody2D> ().AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); } if (Sword.activeSelf == true) { if (Input.GetAxis("Fire1_P1") > 0 && Animation1.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP1"); Swing.Play(); Animation1.SetTrigger("ButtonPress"); } } else if (MegaSword.activeSelf == true) { if (Input.GetAxis("Fire1_P1") > 0 && Animation2.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP1"); Swing.Play(); Animation2.SetTrigger("ButtonPress"); } } if (player1Health == 3) { PH4.gameObject.SetActive(true); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(false); PH11.gameObject.SetActive(false); PH5.gameObject.SetActive(false); respawn1 = false; } else if (player1Health == 2) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(true); PH2.gameObject.SetActive(false); PH11.gameObject.SetActive(false); respawn2 = false; if (respawn1 == false) { Respawn(); respawn1 = true; } } else if (player1Health == 1) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(true); PH11.gameObject.SetActive(false); if (respawn2 == false) { Respawn(); respawn2 = true; } } } else if (player2) { if (Input.GetAxis("Horizontal_P2") > 0) { gameObject.transform.position += transform.right * Time.deltaTime * speed; if (facingright != true) { //SR.flipX = false; transform.localScale += new Vector3(+flipNumber, 0, 0); facingright = true; } } if (Input.GetAxis("Horizontal_P2") < 0) { gameObject.transform.position += -transform.right * Time.deltaTime * speed; if (facingright == true) { //SR.flipX = true; transform.localScale += new Vector3(-flipNumber, 0, 0); facingright = false; } } if (Input.GetAxis("Jump_P2") > 0 && GetComponent <Rigidbody2D> ().velocity.y == 0) { GetComponent <Rigidbody2D> ().AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); } if (Sword.activeSelf == true) { if (Input.GetAxis("Fire1_P2") > 0 && Animation1.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP2"); Swing.Play(); Animation1.SetTrigger("ButtonPress"); } } else if (MegaSword.activeSelf == true) { if (Input.GetAxis("Fire1_P2") > 0 && Animation2.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP2"); Swing.Play(); Animation2.SetTrigger("ButtonPress"); } } if (player2Health == 3) { PH4.gameObject.SetActive(true); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(false); PH21.gameObject.SetActive(false); PH5.gameObject.SetActive(false); respawn3 = false; } else if (player2Health == 2) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(true); PH2.gameObject.SetActive(false); PH21.gameObject.SetActive(false); respawn4 = false; if (respawn3 == false) { Respawn(); respawn3 = true; } } else if (player2Health == 1) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(true); PH21.gameObject.SetActive(false); if (respawn4 == false) { Respawn(); respawn4 = true; } } } else if (player3) { if (Input.GetAxis("Horizontal_P3") > 0) { gameObject.transform.position += transform.right * Time.deltaTime * speed; if (facingright != true) { //SR.flipX = false; transform.localScale += new Vector3(+flipNumber, 0, 0); facingright = true; } } if (Input.GetAxis("Horizontal_P3") < 0) { gameObject.transform.position += -transform.right * Time.deltaTime * speed; if (facingright == true) { //SR.flipX = true; transform.localScale += new Vector3(-flipNumber, 0, 0); facingright = false; } } if (Input.GetAxis("Jump_P3") > 0 && GetComponent <Rigidbody2D> ().velocity.y == 0) { GetComponent <Rigidbody2D> ().AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); } if (Sword.activeSelf == true) { if (Input.GetAxis("Fire_P3") > 0 && Animation1.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP3"); Swing.Play(); Animation1.SetTrigger("ButtonPress"); } } else if (MegaSword.activeSelf == true) { if (Input.GetAxis("Fire_P3") > 0 && Animation2.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP3"); Swing.Play(); Animation2.SetTrigger("ButtonPress"); } } if (player3Health == 3) { PH4.gameObject.SetActive(true); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(false); PH31.gameObject.SetActive(false); PH5.gameObject.SetActive(false); respawn3 = false; } else if (player3Health == 2) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(true); PH2.gameObject.SetActive(false); PH31.gameObject.SetActive(false); respawn4 = false; if (respawn3 == false) { Respawn(); respawn3 = true; } } else if (player3Health == 1) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(true); PH31.gameObject.SetActive(false); if (respawn4 == false) { Respawn(); respawn4 = true; } } } else if (player4) { if (Input.GetAxis("Horizontal_P4") > 0) { gameObject.transform.position += transform.right * Time.deltaTime * speed; if (facingright != true) { //SR.flipX = false; transform.localScale += new Vector3(+flipNumber, 0, 0); facingright = true; } } if (Input.GetAxis("Horizontal_P4") < 0) { gameObject.transform.position += -transform.right * Time.deltaTime * speed; if (facingright == true) { //SR.flipX = true; transform.localScale += new Vector3(-flipNumber, 0, 0); facingright = false; } } if (Input.GetAxis("Jump_P4") > 0 && GetComponent <Rigidbody2D> ().velocity.y == 0) { GetComponent <Rigidbody2D> ().AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); } if (Sword.activeSelf == true) { if (Input.GetAxis("Fire_P4") > 0 && Animation1.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP4"); Swing.Play(); Animation1.SetTrigger("ButtonPress"); } } else if (MegaSword.activeSelf == true) { if (Input.GetAxis("Fire_P4") > 0 && Animation2.GetCurrentAnimatorStateInfo(0).IsName("New State")) { Debug.Log("SwingP4"); Swing.Play(); Animation2.SetTrigger("ButtonPress"); } } if (player4Health == 3) { PH4.gameObject.SetActive(true); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(false); PH41.gameObject.SetActive(false); PH5.gameObject.SetActive(false); respawn3 = false; } else if (player4Health == 2) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(true); PH2.gameObject.SetActive(false); PH41.gameObject.SetActive(false); respawn4 = false; if (respawn3 == false) { Respawn(); respawn3 = true; } } else if (player4Health == 1) { PH4.gameObject.SetActive(false); PH3.gameObject.SetActive(false); PH2.gameObject.SetActive(true); PH41.gameObject.SetActive(false); if (respawn4 == false) { Respawn(); respawn4 = true; } } } if (player1Health == 0 && P1Attacked == true) { PH11.gameObject.SetActive(true); player1dead = true; if (player2Health >= 1 && player3Health >= 1 && player4Health >= 1) { if (added2 == false) { PlayerPrefs.SetInt("Player1LoseStreak", PlayerPrefs.GetInt("Player1LoseStreak") + 1); PlayerPrefs.SetInt("Player2LoseStreak", 0); PlayerPrefs.SetInt("Player3LoseStreak", 0); PlayerPrefs.SetInt("Player4LoseStreak", 0); added2 = true; } } P1.gameObject.SetActive(false); } if (player2Health == 0 && P2Attacked == true) { PH21.gameObject.SetActive(true); player2dead = true; if (player1Health >= 1 && player3Health >= 1 && player4Health >= 1) { if (added2 == false) { PlayerPrefs.SetInt("Player2LoseStreak", PlayerPrefs.GetInt("Player2LoseStreak") + 1); PlayerPrefs.SetInt("Player1LoseStreak", 0); PlayerPrefs.SetInt("Player3LoseStreak", 0); PlayerPrefs.SetInt("Player4LoseStreak", 0); added2 = true; } } P2.gameObject.SetActive(false); } if (player3Health == 0 && P3Attacked == true) { PH31.gameObject.SetActive(true); player3dead = true; if (player2Health >= 1 && player1Health >= 1 && player4Health >= 1) { if (added2 == false) { PlayerPrefs.SetInt("Player3LoseStreak", PlayerPrefs.GetInt("Player3LoseStreak") + 1); PlayerPrefs.SetInt("Player2LoseStreak", 0); PlayerPrefs.SetInt("Player1LoseStreak", 0); PlayerPrefs.SetInt("Player4LoseStreak", 0); added2 = true; } } P3.gameObject.SetActive(false); } if (player4Health == 0 && P4Attacked == true) { PH41.gameObject.SetActive(true); player4dead = true; if (player2Health >= 1 && player3Health >= 1 && player1Health >= 1) { if (added2 == false) { PlayerPrefs.SetInt("Player4LoseStreak", PlayerPrefs.GetInt("Player4LoseStreak") + 1); PlayerPrefs.SetInt("Player2LoseStreak", 0); PlayerPrefs.SetInt("Player3LoseStreak", 0); PlayerPrefs.SetInt("Player1LoseStreak", 0); added2 = true; } } P4.gameObject.SetActive(false); } }