Jump to content
  • Advertisement

sidbhati32

Member
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

102 Neutral

About sidbhati32

  • Rank
    Member

Personal Information

  • Interests
    Programming

Recent Profile Visitors

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

  1. Aaaye, Thanks Man. I implemented it but again as you said it needs to do some calculations as the player changes its position with time. Anything you had like to suggest me to resolve this?
  2. I just want to shoot towards the enemy so I guess I wouldn't require the distance. I guess I would require the directional vector of my enemy towards the player right? or I would need to do something with the angle?
  3. There are two Entities in the game and we controlling one of them. The other entity moves in a particular direction throughout the game and I want to make the AI like the enemy shoots at my player after some duration of time. I am using Directx 10 SDK for this. I think I would need to calculate the distance between the two entities and shoot it towards the player. I would need to calculate the distance between the two vectors and direction of A towards B. How to calculate the direction between the two?
  4. How do I detect the mouse event of moving my mouse left or right and wheel up or down? I have used Get_X_LParam for mouse movement and WParam for wheel movement. Like DWORD x = HIWORD(wParam) but both of these events return continuous values. for eg. if(x>0) { //do this } else { //do this } the Wparam only returns the same value every time even if I am moving my wheel downwards. Same with Get_X_LParam
  5. sidbhati32

    C++ Game Asteroid

    Yeah it is. Kind of an assignment or a test you can say. But no problem. You can give me hints for doing it either? It will land me a job, that's what I want to say.
  6. sidbhati32

    C++ Game Asteroid

    Hey Alvaro. Thanks for going through the code but this is a test that I have got. I am supposed to find the bugs in this code and something is forcing the build to crash. But I'll honestly let them know a more optimized code for the given. Anyways the main issue is the bug. I have already fixed a few but I can't know what is causing this game to crash Thanks
  7. sidbhati32

    C++ Game Asteroid

    [ #include "Game.h" #include "System.h" #include "OrthoCamera.h" #include "Background.h" #include "Ship.h" #include "Asteroid.h" #include "Explosion.h" #include "Keyboard.h" #include "Random.h" #include "Maths.h" #include "Bullet.h" #include "Collision.h" #include <algorithm> Game::Game() : camera_(0), background_(0), player_(0), collision_(0) { camera_ = new OrthoCamera(); camera_->SetPosition(D3DXVECTOR3(0.0f, 0.0f, 0.0f)); camera_->SetFrustum(800.0f, 600.0f, -100.0f, 100.0f); background_ = new Background(800.0f, 600.0f); collision_ = new Collision(); } Game::~Game() { delete camera_; delete background_; delete player_; DeleteBullet(); DeleteAllAsteroids(); DeleteAllExplosions(); delete collision_; } void Game::Update(System *system) { UpdatePlayer(system); UpdateAsteroids(system); UpdateBullet(system); UpdateCollisions(); } void Game::RenderBackgroundOnly(Graphics *graphics) { camera_->SetAsView(graphics); background_->Render(graphics); } void Game::RenderEverything(Graphics *graphics) { camera_->SetAsView(graphics); background_->Render(graphics); if (player_) { player_->Render(graphics); } for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { (*asteroidIt)->Render(graphics); } if (bullet_) //**TODO: Candidate for crash { bullet_->Render(graphics); } for (ExplosionList::const_iterator explosionIt = explosions_.begin(), end = explosions_.end(); explosionIt != end; ++explosionIt) { (*explosionIt)->Render(graphics); } } void Game::InitialiseLevel(int numAsteroids) { DeleteAllAsteroids(); DeleteAllExplosions(); SpawnPlayer(); SpawnAsteroids(numAsteroids); } bool Game::IsLevelComplete() const { return (asteroids_.empty() && explosions_.empty()); } bool Game::IsGameOver() const { return (player_ == 0 && explosions_.empty()); } void Game::DoCollision(GameEntity *a, GameEntity *b) { Ship *player = static_cast<Ship *>(a == player_ ? a : (b == player_ ? b : 0)); Bullet *bullet = static_cast<Bullet *>(a == bullet_ ? a : (b == bullet_ ? b : 0)); Asteroid *asteroid = static_cast<Asteroid *>(IsAsteroid(a) ? a : (IsAsteroid(b) ? b : 0)); if (player && asteroid) { AsteroidHit(asteroid); DeletePlayer(); } if (bullet && asteroid) { AsteroidHit(asteroid); DeleteBullet(); } } void Game::SpawnPlayer() { DeletePlayer(); player_ = new Ship(); player_->EnableCollisions(collision_, 10.0f); } void Game::DeletePlayer() { delete player_; player_ = 0; } void Game::UpdatePlayer(System *system) { if (player_ == 0) return; Keyboard *keyboard = system->GetKeyboard(); float acceleration = 0.0f; if (keyboard->IsKeyHeld(VK_UP) || keyboard->IsKeyHeld('W')) { acceleration = 1.0f; } else if (keyboard->IsKeyHeld(VK_DOWN) || keyboard->IsKeyHeld('S')) { acceleration = -1.0f; } float rotation = 0.0f; if (keyboard->IsKeyHeld(VK_RIGHT) || keyboard->IsKeyHeld('D')) { rotation = -1.0f; } else if (keyboard->IsKeyHeld(VK_LEFT) || keyboard->IsKeyHeld('A')) { rotation = 1.0f; } player_->SetControlInput(acceleration, rotation); player_->Update(system); WrapEntity(player_); if (keyboard->IsKeyPressed(VK_SPACE)) { D3DXVECTOR3 playerForward = player_->GetForwardVector(); D3DXVECTOR3 bulletPosition = player_->GetPosition() + playerForward * 10.0f; SpawnBullet(bulletPosition, playerForward); } } void Game::UpdateAsteroids(System *system) { for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { (*asteroidIt)->Update(system); WrapEntity(*asteroidIt); } } void Game::UpdateBullet(System *system) { if (bullet_) { bullet_->Update(system); WrapEntity(bullet_); } } void Game::WrapEntity(GameEntity *entity) const { D3DXVECTOR3 entityPosition = entity->GetPosition(); entityPosition.x = Maths::WrapModulo(entityPosition.x, -400.0f, 400.0f); entityPosition.y = Maths::WrapModulo(entityPosition.y, -300.0f, 300.0f); entity->SetPosition(entityPosition); } void Game::DeleteAllAsteroids() { for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { delete (*asteroidIt); } asteroids_.clear(); } void Game::DeleteAllExplosions() { for (ExplosionList::const_iterator explosionIt = explosions_.begin(), end = explosions_.end(); explosionIt != end; ++explosionIt) { delete (*explosionIt); } explosions_.clear(); } void Game::SpawnBullet(const D3DXVECTOR3 &position, const D3DXVECTOR3 &direction) { DeleteBullet(); bullet_ = new Bullet(position, direction); bullet_->EnableCollisions(collision_, 3.0f); } void Game::DeleteBullet() { delete bullet_; bullet_ = 0; } void Game::SpawnAsteroids(int numAsteroids) { float halfWidth = 800.0f * 0.5f; float halfHeight = 600.0f * 0.5f; for (int i = 0; i < numAsteroids; i++) { float x = Random::GetFloat(-halfWidth, halfWidth); float y = Random::GetFloat(-halfHeight, halfHeight); D3DXVECTOR3 position = D3DXVECTOR3(x, y, 0.0f); SpawnAsteroidAt(position, 3); } } void Game::SpawnAsteroidAt(const D3DXVECTOR3 &position, int size) { const float MAX_ASTEROID_SPEED = 1.0f; float angle = Random::GetFloat(Maths::TWO_PI); D3DXMATRIX randomRotation; D3DXMatrixRotationZ(&randomRotation, angle); D3DXVECTOR3 velocity = D3DXVECTOR3(0.0f, Random::GetFloat(MAX_ASTEROID_SPEED), 0.0f); D3DXVec3TransformNormal(&velocity, &velocity, &randomRotation); Asteroid *asteroid = new Asteroid(position, velocity, size); asteroid->EnableCollisions(collision_, size * 5.0f); asteroids_.push_back(asteroid); } bool Game::IsAsteroid(GameEntity *entity) const { return (std::find(asteroids_.begin(), asteroids_.end(), entity) != asteroids_.end()); } void Game::AsteroidHit(Asteroid *asteroid) { int oldSize = asteroid->GetSize(); if (oldSize > 1) { int smallerSize = oldSize -1; D3DXVECTOR3 position = asteroid->GetPosition(); SpawnAsteroidAt(position, smallerSize); SpawnAsteroidAt(position, smallerSize); } DeleteAsteroid(asteroid); } void Game::DeleteAsteroid(Asteroid *asteroid) { asteroids_.remove(asteroid); delete asteroid; } void Game::UpdateCollisions() { collision_->DoCollisions(this); } ] this the code of Game.cpp #include "Bullet.h" #include "Graphics.h" Bullet::Bullet(const D3DXVECTOR3 &position, const D3DXVECTOR3 &direction) { const float BULLET_SPEED = 4.0f; SetPosition(position); D3DXVECTOR3 normalisedDirection; D3DXVec3Normalize(&normalisedDirection, &direction); velocity_ = normalisedDirection * BULLET_SPEED; } void Bullet::Update(System *system) { D3DXVECTOR3 position = GetPosition(); D3DXVec3Add(&position, &position, &velocity_); SetPosition(position); } void Bullet::Render(Graphics *graphics) const { const float RADIUS = 3.0f; struct DummyVert { float x, y, z; D3DCOLOR diffuse; }; DummyVert square[5] = { {-RADIUS, -RADIUS, 0.0f, 0xffffffff}, {-RADIUS, RADIUS, 0.0f, 0xffffffff}, { RADIUS, RADIUS, 0.0f, 0xffffffff}, { RADIUS, -RADIUS, 0.0f, 0xffffffff}, {-RADIUS, -RADIUS, 0.0f, 0xffffffff}, }; D3DXVECTOR3 position = GetPosition(); D3DXMATRIX translationMatrix; D3DXMatrixTranslation(&translationMatrix, position.x, position.y, position.z); D3DXMATRIX identityMatrix; D3DXMatrixIdentity(&identityMatrix); DWORD dummyFvf = D3DFVF_XYZ | D3DFVF_DIFFUSE; graphics->SetVertexFormat(dummyFvf); graphics->DisableLighting(); graphics->SetModelMatrix(&translationMatrix); graphics->DrawImmediate(D3DPT_LINESTRIP, 4, &square[0], sizeof(square[0])); graphics->SetModelMatrix(&identityMatrix); graphics->EnableLighting(); } this is of Bullet.cpp #include "Bullet.h" #include "Graphics.h" Bullet::Bullet(const D3DXVECTOR3 &position, const D3DXVECTOR3 &direction) { const float BULLET_SPEED = 4.0f; SetPosition(position); D3DXVECTOR3 normalisedDirection; D3DXVec3Normalize(&normalisedDirection, &direction); velocity_ = normalisedDirection * BULLET_SPEED; } void Bullet::Update(System *system) { D3DXVECTOR3 position = GetPosition(); D3DXVec3Add(&position, &position, &velocity_); SetPosition(position); } void Bullet::Render(Graphics *graphics) const { const float RADIUS = 3.0f; struct DummyVert { float x, y, z; D3DCOLOR diffuse; }; DummyVert square[5] = { {-RADIUS, -RADIUS, 0.0f, 0xffffffff}, {-RADIUS, RADIUS, 0.0f, 0xffffffff}, { RADIUS, RADIUS, 0.0f, 0xffffffff}, { RADIUS, -RADIUS, 0.0f, 0xffffffff}, {-RADIUS, -RADIUS, 0.0f, 0xffffffff}, }; D3DXVECTOR3 position = GetPosition(); D3DXMATRIX translationMatrix; D3DXMatrixTranslation(&translationMatrix, position.x, position.y, position.z); D3DXMATRIX identityMatrix; D3DXMatrixIdentity(&identityMatrix); DWORD dummyFvf = D3DFVF_XYZ | D3DFVF_DIFFUSE; graphics->SetVertexFormat(dummyFvf); graphics->DisableLighting(); graphics->SetModelMatrix(&translationMatrix); graphics->DrawImmediate(D3DPT_LINESTRIP, 4, &square[0], sizeof(square[0])); graphics->SetModelMatrix(&identityMatrix); graphics->EnableLighting(); } Bullet.cpp #include "Game.h" #include "System.h" #include "OrthoCamera.h" #include "Background.h" #include "Ship.h" #include "Asteroid.h" #include "Explosion.h" #include "Keyboard.h" #include "Random.h" #include "Maths.h" #include "Bullet.h" #include "Collision.h" #include <algorithm> Game::Game() : camera_(0), background_(0), player_(0), collision_(0) { camera_ = new OrthoCamera(); camera_->SetPosition(D3DXVECTOR3(0.0f, 0.0f, 0.0f)); camera_->SetFrustum(800.0f, 600.0f, -100.0f, 100.0f); background_ = new Background(800.0f, 600.0f); collision_ = new Collision(); } Game::~Game() { delete camera_; delete background_; delete player_; DeleteBullet(); DeleteAllAsteroids(); DeleteAllExplosions(); delete collision_; } void Game::Update(System *system) { UpdatePlayer(system); UpdateAsteroids(system); UpdateBullet(system); UpdateCollisions(); } void Game::RenderBackgroundOnly(Graphics *graphics) { camera_->SetAsView(graphics); background_->Render(graphics); } void Game::RenderEverything(Graphics *graphics) { camera_->SetAsView(graphics); background_->Render(graphics); if (player_) { player_->Render(graphics); } for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { (*asteroidIt)->Render(graphics); } if (bullet_) //**TODO: Candidate for crash { bullet_->Render(graphics); } for (ExplosionList::const_iterator explosionIt = explosions_.begin(), end = explosions_.end(); explosionIt != end; ++explosionIt) { (*explosionIt)->Render(graphics); } } void Game::InitialiseLevel(int numAsteroids) { DeleteAllAsteroids(); DeleteAllExplosions(); SpawnPlayer(); SpawnAsteroids(numAsteroids); } bool Game::IsLevelComplete() const { return (asteroids_.empty() && explosions_.empty()); } bool Game::IsGameOver() const { return (player_ == 0 && explosions_.empty()); } void Game::DoCollision(GameEntity *a, GameEntity *b) { Ship *player = static_cast<Ship *>(a == player_ ? a : (b == player_ ? b : 0)); Bullet *bullet = static_cast<Bullet *>(a == bullet_ ? a : (b == bullet_ ? b : 0)); Asteroid *asteroid = static_cast<Asteroid *>(IsAsteroid(a) ? a : (IsAsteroid(b) ? b : 0)); if (player && asteroid) { AsteroidHit(asteroid); DeletePlayer(); } if (bullet && asteroid) { AsteroidHit(asteroid); DeleteBullet(); } } void Game::SpawnPlayer() { DeletePlayer(); player_ = new Ship(); player_->EnableCollisions(collision_, 10.0f); } void Game::DeletePlayer() { delete player_; player_ = 0; } void Game::UpdatePlayer(System *system) { if (player_ == 0) return; Keyboard *keyboard = system->GetKeyboard(); float acceleration = 0.0f; if (keyboard->IsKeyHeld(VK_UP) || keyboard->IsKeyHeld('W')) { acceleration = 1.0f; } else if (keyboard->IsKeyHeld(VK_DOWN) || keyboard->IsKeyHeld('S')) { acceleration = -1.0f; } float rotation = 0.0f; if (keyboard->IsKeyHeld(VK_RIGHT) || keyboard->IsKeyHeld('D')) { rotation = -1.0f; } else if (keyboard->IsKeyHeld(VK_LEFT) || keyboard->IsKeyHeld('A')) { rotation = 1.0f; } player_->SetControlInput(acceleration, rotation); player_->Update(system); WrapEntity(player_); if (keyboard->IsKeyPressed(VK_SPACE)) { D3DXVECTOR3 playerForward = player_->GetForwardVector(); D3DXVECTOR3 bulletPosition = player_->GetPosition() + playerForward * 10.0f; SpawnBullet(bulletPosition, playerForward); } } void Game::UpdateAsteroids(System *system) { for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { (*asteroidIt)->Update(system); WrapEntity(*asteroidIt); } } void Game::UpdateBullet(System *system) { if (bullet_) { bullet_->Update(system); WrapEntity(bullet_); } } void Game::WrapEntity(GameEntity *entity) const { D3DXVECTOR3 entityPosition = entity->GetPosition(); entityPosition.x = Maths::WrapModulo(entityPosition.x, -400.0f, 400.0f); entityPosition.y = Maths::WrapModulo(entityPosition.y, -300.0f, 300.0f); entity->SetPosition(entityPosition); } void Game::DeleteAllAsteroids() { for (AsteroidList::const_iterator asteroidIt = asteroids_.begin(), end = asteroids_.end(); asteroidIt != end; ++asteroidIt) { delete (*asteroidIt); } asteroids_.clear(); } void Game::DeleteAllExplosions() { for (ExplosionList::const_iterator explosionIt = explosions_.begin(), end = explosions_.end(); explosionIt != end; ++explosionIt) { delete (*explosionIt); } explosions_.clear(); } void Game::SpawnBullet(const D3DXVECTOR3 &position, const D3DXVECTOR3 &direction) { DeleteBullet(); bullet_ = new Bullet(position, direction); bullet_->EnableCollisions(collision_, 3.0f); } void Game::DeleteBullet() { delete bullet_; bullet_ = 0; } void Game::SpawnAsteroids(int numAsteroids) { float halfWidth = 800.0f * 0.5f; float halfHeight = 600.0f * 0.5f; for (int i = 0; i < numAsteroids; i++) { float x = Random::GetFloat(-halfWidth, halfWidth); float y = Random::GetFloat(-halfHeight, halfHeight); D3DXVECTOR3 position = D3DXVECTOR3(x, y, 0.0f); SpawnAsteroidAt(position, 3); } } void Game::SpawnAsteroidAt(const D3DXVECTOR3 &position, int size) { const float MAX_ASTEROID_SPEED = 1.0f; float angle = Random::GetFloat(Maths::TWO_PI); D3DXMATRIX randomRotation; D3DXMatrixRotationZ(&randomRotation, angle); D3DXVECTOR3 velocity = D3DXVECTOR3(0.0f, Random::GetFloat(MAX_ASTEROID_SPEED), 0.0f); D3DXVec3TransformNormal(&velocity, &velocity, &randomRotation); Asteroid *asteroid = new Asteroid(position, velocity, size); asteroid->EnableCollisions(collision_, size * 5.0f); asteroids_.push_back(asteroid); } bool Game::IsAsteroid(GameEntity *entity) const { return (std::find(asteroids_.begin(), asteroids_.end(), entity) != asteroids_.end()); } void Game::AsteroidHit(Asteroid *asteroid) { int oldSize = asteroid->GetSize(); if (oldSize > 1) { int smallerSize = oldSize -1; D3DXVECTOR3 position = asteroid->GetPosition(); SpawnAsteroidAt(position, smallerSize); SpawnAsteroidAt(position, smallerSize); } DeleteAsteroid(asteroid); } void Game::DeleteAsteroid(Asteroid *asteroid) { asteroids_.remove(asteroid); delete asteroid; } void Game::UpdateCollisions() { collision_->DoCollisions(this); } this is Game.cpp
  8. Hey guys, I am getting an exception when I run my code. It's an asteroid game and I am using VS2012 express for it. When I run my code I get this warning dialogue box and then it takes me to UpdateBullet function.
  9. Hello, I am using unity and I am confused on one part It's like I have three buttons out of which one has to be selected. If I have selected one of the three buttons during runtime and then I want to select the other button. How would Unity know that only one button has to be selected out of the three and unity has to disable the older selected button now? There must be some function to make unity know that it has to deselect the older option and select the newer one? I have attached a screen shot along with this. Thanks
  10. Okay, so I am making a character controller in Unity of a 3D model. it got two layers of animation - the base layer works perfectly fine but the 1st layer in which the character holds a flash light. The animation works fine until the arm starts behaving weirdly when the shoulder is rotated upside or downwards. I am attaching a video along with this https://drive.google.com/open?id=1hLFx3Szx4au4-2PZaAEa3d1f8kNmWMUH if someone knows how to do it then please let me know. It would be a great help I have used IK for this. Set the IK target to the torch but it still didn't work
  11. @Scouting Ninja Hey, Thanks for taking your time out to explain me this thing.
  12. 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

  13. @Scouting Ninja Sure Sir, I have to submit this by 21st, see if you can help me before the date else no problem. Thanks for the help If you can link me to any tutorial that will help me in my case, it would be a great help.
  14. @Scouting Ninja @Cold.bo @Mike2343 I have progressed a bit with the project - 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
  15. @Scouting Ninja Yeah collision is not a problem. Suppose I have got a word "Random" and three spheres having different alphabets must fall down. At least one them should be from the word "Random". How am I supposed to link the word generated with the the alphabets falling down? Suppose "A","S","P" fall down and I interact with A then how would Unity know that A is a correct alphabet?
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!