private void OnTriggerEnter2D(Collider2D other) { // is it a virus? if (other.CompareTag("virus")) { // find where on the grid this is Vector3Int position = grid.WorldToCell(rayFrom.position); tilemap.SetTile(position, null); // set tile at this position as null rb.velocity = Vector2.zero; // stop any movement chipstate = ChipStates.SCAN; // resume scan } }
void Scan() { rb.angularVelocity = turnSpeed; Vector3 forward = transform.TransformDirection(Vector3.up) * rayDistance; rb.velocity = transform.up * 0.3f; // test for any hits RaycastHit2D hit = Physics2D.Raycast(rayFrom.position, forward, rayDistance, rayCastOn); if (hit.collider != null) { Debug.Log($"Hit {hit.collider.name}"); // draw red if hit Debug.DrawRay(rayFrom.position, forward, Color.red); rb.angularVelocity = 0; chipstate = ChipStates.CLEAN; } else { // draws green if no hit Debug.DrawRay(rayFrom.position, forward, Color.green); } }