private void Update() { if (isPaused) { return; } if (Time.time - timerLast > timer) { _image.sizeDelta = new Vector2(60, 60); timerLast = Time.time; } if (Time.time - lastSpawn > deltaSpawn) { Vegetable v = GetVegetable(); float randomX = Random.Range(-1.65f, 1.65f); float rand = Random.Range(0f, 1f); v.LaunchVegetable(Random.Range(1.8f, 2.8f), randomX, -randomX, rand); lastSpawn = Time.time; } if (Input.GetMouseButtonDown(0)) { AudioSource.PlayClipAtPoint(sound_miss, transform.position); } if (Input.GetMouseButton(0)) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); pos.z = -1; trail.position = pos; Collider2D[] thisFramesVeggie = Physics2D.OverlapPointAll(new Vector2(pos.x, pos.y), LayerMask.GetMask("Vegetable")); if ((Input.mousePosition - lastMousePos).sqrMagnitude > SLICE_FORCE) { foreach (Collider2D c2 in thisFramesVeggie) { for (var i = 0; i < veggiesCols.Length; i++) { if (c2 == veggiesCols[i]) { int hit = c2.GetComponent <Vegetable>().Slice(); if (hit == 1) { AudioSource.PlayClipAtPoint(sound_hit, transform.position); _image.sizeDelta = new Vector2(70, 70); } } } } } lastMousePos = Input.mousePosition; veggiesCols = thisFramesVeggie; } }
private void Update() { if (isPaused) { return; } if (Time.time - lastSpawn > deltaSpawn) { Vegetable v = GetVegetable(); float randomX = Random.Range(-1.65f, 1.65f); v.LaunchVegetable(Random.Range(1.85f, 2.75f), randomX, -randomX); lastSpawn = Time.time; } if (Input.GetMouseButton(0)) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); pos.z = -1; trail.position = pos; Collider2D[] thisFramesVeggie = Physics2D.OverlapPointAll(new Vector2(pos.x, pos.y), LayerMask.GetMask("Vegetable")); if ((Input.mousePosition - lastMousePos).sqrMagnitude > requiredsliceforce) { foreach (Collider2D c2 in thisFramesVeggie) { for (int i = 0; i < veggiesCols.Length; i++) { if (c2 == veggiesCols[i]) { c2.GetComponent <Vegetable>().Slice(); } } } } veggiesCols = thisFramesVeggie; lastMousePos = Input.mousePosition; } }