using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.UI; public class Fruit : MonoBehaviour { public GameObject SlicedFruit; public bool Ended = false; public float force = 10f; public static int score; public Text txtScore; Rigidbody2D rig; public static Fruit instance; public Text text1, text2, text3; // Start is called before the first frame update void Start() { text1 = GameObject.Find("Text").GetComponent(); text2 = GameObject.Find("TextStage2").GetComponent(); text3 = GameObject.Find("TextStage3").GetComponent(); rig = GetComponent(); rig.AddForce(transform.up * force, ForceMode2D.Impulse); txtScore = GameObject.Find("score").GetComponent(); } void Update() { txtScore.text = score.ToString(); } public void End(bool Won) { if (!Ended) { if (Won) { Animator wonAnime = GameObject.Find("YouWinPanel").GetComponent(); wonAnime.SetBool("done", true); } else { Animator LostAnime = GameObject.Find("GameOverPanel").GetComponent(); LostAnime.SetBool("done", true); } Ended = true; } } void OnTriggerEnter2D(Collider2D coll) { if(coll.tag == "Blade") { Debug.Log("a"); Vector2 direction = (coll.transform.position - transform.position).normalized; Quaternion rotation = Quaternion.LookRotation(direction); CheckedR(); GameObject slicedfruit = Instantiate(SlicedFruit); slicedfruit.transform.position = transform.position; Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 dir = mousepos - slicedfruit.transform.position; float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg; slicedfruit.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); slicedfruit.transform.Rotate(new Vector3(0, 0, -90)); Destroy(slicedfruit, 3f); Destroy(gameObject); } } public void pontuacao(int qtdPontos) { score = score + qtdPontos; txtScore.text = score.ToString(); } void CheckedR() { if(ControllerSpwanStage.stage == 0) { if (gameObject.name == text1.GetComponent().text) { Debug.Log("Certo"); pontuacao(1); } else { Debug.Log("Errado"); } } if(ControllerSpwanStage.stage == 1) { if (gameObject.name == text2.GetComponent().text) { Debug.Log("Certo"); pontuacao(1); } else { Debug.Log("Errado"); } } if(ControllerSpwanStage.stage == 2) { if (gameObject.name == text3.GetComponent().text) { Debug.Log("Certo"); pontuacao(1); } else { Debug.Log("Errado"); } } } }