Hit count not working

I am trying to resize the images like this - YouTube
4:44~4:47

I used a list to detect whether the hits are on the same object to resize it but the hits.count on line:25 is always 0 not remembering line:60 hits.count

How can i fix this?

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

public class Hitting : MonoBehaviour {
    private RaycastHit2D hit;
    public GameObject hittingObj;
    

    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            List<GameObject> hits = new List<GameObject>();
            Debug.Log("*********************start***********");

            //move, resize, rotate by touchs
            for (int ii = 0; ii < Input.touchCount; ii++) {
                Debug.Log("input touch[ "+ii+"]/all "+ Input.touchCount);
                Vector2 test = Camera.main.ScreenToWorldPoint(Input.GetTouch(ii).position);
                RaycastHit2D hit = Physics2D.Raycast(test, (Input.GetTouch(ii).position));

                Debug.Log("hits.count-------------------- "+hits.Count);
                if (hit.collider)
                {
                    //do stuff
                    //Debug.DrawLine(test, hit.transform.position, Color.red, 0.1f, true);

                    //move obj
                    hittingObj = (hit.transform.gameObject);
                    bool hitSameObj = false;

                    //click on same obj?
                    Debug.Log("hitting img " + hittingObj.name);
                    foreach (GameObject jj in hits )
                    {
                        Debug.Log("saved hits are "+jj.name);
                        if (hittingObj.name == jj.name)
                        {
                            hitSameObj = true;
                        }
                    }
                    
                    if (hitSameObj)
                    {
                        Debug.Log("do rotate or resize");
                    }
                    else
                    {
                        //move
                        if (Math.Abs(Input.touches[ii].deltaPosition.x) < 30 && Math.Abs(Input.touches[ii].deltaPosition.y) < 10)
                        {
                            hittingObj.transform.position = Input.GetTouch(ii).position;
                        }
                    }
                    
                    hits.Add(hittingObj);
                    Debug.Log("======after add this hit, hit.count: "+hits.Count);
                    foreach (GameObject jj in hits)
                    {
                        Debug.Log("stored hits are "+jj.name);
                    }
                    
                }//if (hit.collider)

                
            }
            Debug.Log("*********************end************");
        } else
        {
            hittingObj = null;
        }
    }
}

part of console.log

*********************start***********
input touch[: 0]/2
hits.count-------------------- 0
hitting img 57735399.1121
======after add this hit, hit.count: 1
stored hits are 57735399.1121
input touch[: 1]/2
hits.count-------------------- 1
hitting img 57737302.221
saved hits are 57735399.1121
======after add this hit, hit.count: 2
stored hits are 57735399.1121
stored hits are 57737302.221
*********************end************
*********************start***********
input touch[: 0]/2
hits.count-------------------- 0
hitting img 57735399.1121
======after add this hit, hit.count: 1
stored hits are 57735399.1121
input touch[: 1]/2
hits.count-------------------- 1
hitting img 57737302.221
saved hits are 57735399.1121
======after add this hit, hit.count: 2
stored hits are 57735399.1121
stored hits are 57737302.221
*********************end************
*********************start***********
input touch[: 0]/2
hits.count-------------------- 0
hitting img 57735399.1121
======after add this hit, hit.count: 1
stored hits are 57735399.1121
input touch[: 1]/2
hits.count-------------------- 1
hitting img 57737302.221
saved hits are 57735399.1121
======after add this hit, hit.count: 2
stored hits are 57735399.1121
stored hits are 57737302.221
*********************end************

Hi @tungkengtse
If you see on line 16

List<GameObject> hits = new List<GameObject>();

You are creating a new list each time as you touch on your screen so old list is getting cleared and new list is created. So create new list outside of Update() and try. Or you can also store that hit count in a variable and use it. And your loop is based on your touch count which is 2 usually as you are zooming object with 2 fingers. So it’ll store only 2 hit points each time. I think this is why your hit count is not working and here you’ve to make some changes as per your requirement.