How do I give a creature sight/smell?

In my simulation, there are spherical creatures, food, and viruses (which aren’t actual game objects, just a separate part of the same code). The creatures change color if they are infected, and I want them to be able to see and smell food and other creatures. Creatures have a diameter of one, and food has a diameter of 0.5. Creatures are shown in colors between red and green, and if they are infected, then their color gets a certain level of blue added, depending on a specific virus trait. These are the traits:

bool infected = false;
float moveSpeed = 1f;
float turnSpeed = 0.5;
float sightRange = 2f;
float scentRange = 2f;
int otherInfected = 256; //range is 1 - 256. 1 means that the creature can tell if a creature is infected if it has 1 or more blue added to the rgb scale, and 256 means it can't detect it at all, as the rgb scale is 0 - 255.

I won’t include any other code because it is irrelevant to my current question.

Seems like what you need is some kind of AI state machine so that the creatures have at least 3 states: patrolling and looking for food, seeing the food and going for it, getting infected and changing color.
AI state machine is fairly easy concept to understand and you should find a lot of tutorials for it on the internet.
Good luck!

The Physics.BoxCast method might be of use. It’s like Physics.RayCast except it sends out a block, letting you find anything within a column that extends outward from your creature.

you mixed up the phy and coding each other- 1 but i have a solution to your question!