Question by 
               MoizSafdar · Apr 21, 2016 at 04:48 AM · 
                c#unity 5scripting problemerrorraycast  
              
 
              How to Destroy game object horizontally and vertically , when hit by a Raycast
Hi,i want my Candies destroys on raycast when the matches are same. If there are two and more than two matches so it will be destroyed , The Script Works and destroys the object in vertically , but sometime its does not destroy any candy, who matched and how to destroy same candies horizontally my first time working with raycast , so i want Help in script
This is my GameScene view . You CAn see in the Picture. if same candy has a match in horizontal and vertical so it will be destroyed 
Here is my Script and Thanks to everyone who will help me. I'm very grateful.
     if (Input.GetMouseButtonUp(0))
     {
         RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
         if (hit.collider != null && hit.collider.gameObject == gameObject)
         {
             alloDestroy = true;
         }
     }
 }
 void OnCollisionStay2D(Collision2D coll)
 {
     if (alloDestroy && coll.collider.gameObject.name == this.gameObject.name)
     {
         coll.collider.gameObject.GetComponent<GridItem>().alloDestroy = true;
         StartCoroutine(destroyMyself());
         //if (coll.gameObject != null)
         //Destroy(coll.collider.gameObject);
     }
 }
 IEnumerator destroyMyself()
 {
     yield return new WaitForSeconds(0.01f);
     Destroy(gameObject);
 
                 
                13212.jpg 
                (163.3 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                