Search Unity

I want to destroy actual gameObject using onTouchScreen, but destroy all object - Android Game

Discussion in '2D' started by Bartusiak69, May 30, 2019.

  1. Bartusiak69

    Bartusiak69

    Joined:
    Feb 25, 2019
    Posts:
    1
    Hi !
    I make simple project to the college. It's chicken breaker. Problem is that when I touch screen destroy all chickens, not only one object of chicken with respawned.

    When I touch all this chicken are destroyed.
    I tryied a lot of things from tutorials with YT and I need Idea how to fix It, because still not working.



    Codes:
    upload_2019-5-30_22-38-19.png

    upload_2019-5-30_22-38-37.png

    Chicken Inspector:
    upload_2019-5-30_22-39-32.png

    Thanks for help and sorry for my sick english
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    235
    I am not 100% sure but in your update function ChickenMoveLeft, you have it so if Input.TouchCount>0 then destroy chicken gameobject. The reason I think this is the issue is because that script is on every chicken. It looks like it is saying, if you touch the screen, destroy all objects with that script, regardless where you touch. Also, I dont see any collider components on the chicken gameobject. You need to say something like if I touch the screen, then if my touch hits the collider of the chicken, then destroy the chicken.

    I believe that is where the issue is at, maybe someone else can help me.
     
    Bartusiak69 and N_Murray like this.
  3. N_Murray

    N_Murray

    Joined:
    Apr 1, 2015
    Posts:
    98
    The problem is exactly what cscox has said. The commented out code in your script is the better route for checking if the touch is colliding with your chickens
     
    Bartusiak69 likes this.
unityunity