void OnCollisionEnter2D(Collision2D collision)
    {
        //create a new textbehavior object and update the text component in the game manager
        TextBehavior updateScore    = GameObject.Find("GameManager").GetComponent <TextBehavior>();
        AudioSource  explosionSound = GameObject.Find("GameManager").GetComponent <AudioSource>();

        //check to see if a laser and barrier have collided
        if (this.gameObject.tag == "Laser" && collision.gameObject.tag == "Barrier")
        {
            //destroy the laser
            Destroy(gameObject);
        }

        //check to see if a laser and asteroid have collider with one another
        if (this.gameObject.tag == "Laser" && collision.gameObject.tag == "Asteroid")
        {
            //destroy the laser
            Destroy(gameObject);
        }

        if (this.gameObject.tag == "Asteroid" && collision.gameObject.tag == "Laser")
        {
            //update the score by 1 point
            updateScore.scoreNum += 1;
            //play blow up sound
            explosionSound.Play();
            //destroy the asteroid
            Destroy(gameObject);
            //after collision create an explosion and destory it
            GameObject explosionClone = Instantiate(explosion, gameObject.transform.position, gameObject.transform.rotation);
            Destroy(explosionClone, 1f);
        }
    }
Example #2
0
 public void OnTouch()
 {
     // If a touch is found and we are not waiting,
     if (!touched)
     {
         // Move the object up by 10cm and reset the wait counter.
         touched = true;
         this.gameObject.transform.Translate(new Vector3(0, -0.04f, 0));
         front.SetActive(false);
         TextBehavior.triggerStartGame();
         //GameManager.startGame();
     }
 }
Example #3
0
    public void MakeText(string text, Vector3 Position, Color color, int size, bool ableToMove)
    {
        GameObject   newText    = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <ObjectPool>().GetObjectForType("Text", false);
        TextBehavior textScript = newText.GetComponent <TextBehavior>();

        textScript.SetPosition(Position);
        textScript.SetResetTime(2f);
        textScript.SetAbleToMove(ableToMove);
        Text textComponent = newText.GetComponent <Text>();

        textComponent.text     = text;
        textComponent.fontSize = size;
        textComponent.color    = color;
    }
Example #4
0
    public IEnumerator CreateDialogue(string text, Vector3 position)
    {
        GameObject   newText    = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <ObjectPool>().GetObjectForType("Text", false);
        TextBehavior textScript = newText.GetComponent <TextBehavior>();

        textScript.SetPosition(position);
        textScript.SetAbleToMove(false);
        Text textComponent = newText.GetComponent <Text>();

        textComponent.color = Color.black;
        textComponent.text  = "";
        textScript.SetResetTime(5f);
        char[] allCharsInText = text.ToCharArray();
        foreach (char characters in allCharsInText)
        {
            textComponent.text += characters;
            yield return(new WaitForSeconds(0.04f));
        }
    }
Example #5
0
        public void UpdateText(float value, TextBehavior textBehavior)
        {
            // FLOATING TEXT
            Transform textValueTransform = transform.Find("Canvas/TextValue");

            if (textValueTransform != null)
            {
                TextMeshProUGUI t = textValueTransform.GetComponent <TextMeshProUGUI>();
                if (t != null)
                {
                    t.text = value.ToString("#0");

                    RectTransform trt = textValueTransform.GetComponent <RectTransform>();
                    trt.sizeDelta = new Vector2(radius * 1.6f * 100.0f, radius * 1.6f * 100.0f);

                    if (textBehavior == TextBehavior.Hidden)
                    {
                        trt.localPosition = new Vector3(0, 0, -0.002f);
                        t.gameObject.SetActive(false);
                    }
                    else
                    {
                        if (textBehavior == TextBehavior.Center)
                        {
                            trt.localPosition = new Vector3(0.2f * radius, -0.2f * radius, -0.002f);
                        }
                        else if (textBehavior == TextBehavior.Bottom)
                        {
                            trt.localPosition = new Vector3(0.2f * radius, -2.2f * radius, -0.002f);
                        }
                        else if (textBehavior == TextBehavior.Top)
                        {
                            trt.localPosition = new Vector3(0.2f * radius, 1.8f * radius, -0.002f);
                        }
                        t.gameObject.SetActive(true);
                    }
                }
            }
        }
Example #6
0
 public TextCard() : base()
 {
     this.TextBehavior = new TextBehavior();
 }