public void UpdateTouch(int index, Touch t) { if (touchColliders.Count <= index) { TouchCollider tc = CreateTouchCollider(); tc.name = "touch " + index; tc.transform.SetParent(touchCanvas); touchColliders.Add(tc); } TouchCollider touch = touchColliders[index]; touch.touch = t; touch.MarkValid(true); touch.transform.position = t.position; }
public TouchCollider CreateTouchCollider() { if (prefab_touchCollider == null) { GameObject touchObj = new GameObject("touch"); touchObj.layer = LayerMask.NameToLayer("UI"); touchObj.AddComponent <CircleCollider2D>(); Rigidbody2D r2d = touchObj.AddComponent <Rigidbody2D>(); r2d.bodyType = RigidbodyType2D.Kinematic; prefab_touchCollider = touchObj.AddComponent <TouchCollider>(); prefab_touchCollider.MarkValid(false); } GameObject go = Instantiate(prefab_touchCollider.gameObject); return(go.GetComponent <TouchCollider>()); }