Jump to content
  • Advertisement

ApochPiQ

GDNet Emeritus
  • Content Count

    11213
  • Joined

  • Last visited

Community Reputation

23135 Excellent

4 Followers

About ApochPiQ

  • Rank
    Legend

Personal Information

Social

  • Twitter
    ApochPiQ
  • Github
    apoch

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I have randomly generated spheres having different alphabets and predefined words. 

    Presently, I cannot compare the alphabet in the sphere with the alphabets of the word. 

    Let me show you the code 

     

    For randomly generating different alphabets -

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class GenerateRandom : MonoBehaviour {

        private Text[] Circle;

        // Use this for initialization
        void Start () {

            Circle = GameObject.FindGameObjectWithTag ("Text").GetComponentsInChildren<Text> ();
            char[] S = "qwertyuiopasdfghjklzxcvbnm".ToCharArray ();


            for (int i = 0; i < 3; i++) {
                Circle .text = S [Random.Range (0, 25)].ToString ();


            }
        }    
        // Update is called once per frame
        void Update () {
            
        }
    }
     

     

     

    For Randomly generating a word -

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class RandomWord : MonoBehaviour {

        string[] Words = { "great", "stage", "peak", "street", "please" };

        private Text texter; 
        // Use this for initialization
        void Start () {
            texter = GameObject.FindGameObjectWithTag ("Sphere").GetComponent<Text>();
            texter.text =  Words[Random.Range (0, 4)].ToString();
        }
        
        // Update is called once per frame
        void Update () {
            
        }
    }
     

     

    For collision detection and checking the correct alphabet - 

     

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class Destroy : MonoBehaviour {


        private char[] Check;
        private string Me,You;

        // Use this for initialization
        void Start () {

            Me = GameObject.FindGameObjectWithTag ("Sphere").GetComponent<Text> ().ToString ();


        }
        
        // Update is called once per frame
        void Update () {
            

        }

        void OnCollisionEnter2D(Collision2D other)
        {
            
            int Length = Me.Length;

            Check = Me.ToCharArray ();

            Debug.Log ("Collision");

            if(GameObject.FindWithTag ("Background"))
            {
                You = other.gameObject.GetComponent<Text> ().ToString ();
                if(You != null)
                {
                    for(int i=0 ; i<Length; i++)
                    {
                        if (You == Check .ToString ())
                            Debug.Log ("Matched");

                    }
                }
            }

            Destroy (other.gameObject);

    }
    }

     

     

    Now I am getting the issue in the picture I have shared.

     

    When I double click the error, it redirects me to -

         You = other.gameObject.GetComponent<Text> ().ToString ();

     

    Looking forward to your help :) 

    Thanks 

    Untitled.png

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!