Using CheckSphere to affect another Game Object?

What we are trying to do is check the radius around character and have those GameObjects set to another material(for example, to simply change the color of the GameObject to blue).

Our game is set on a grid of tiles, 10 in each row, 10 rows (10x10). When it is the Player’s turn to move, we want the tiles underneath him to be highlighted blue if they are within his moveRange(which is simply a variable we set). Originally, we sent out a RaycastAll, and it worked well to the left, right, forward, and backwards, but we couldn’t get it working with diagonal movements.

Now we’re trying to use a CheckSphere, but the problem is that we’re not sure how to affect the GameObjects the Sphere is reaching.

Here is the original method, a RaycastAll

function Test ()
{
	var layerMask = 1 << 10;
	var hits : RaycastHit[];
	hits = Physics.RaycastAll (transform.position, Vector3(0,0,1), moveRange, layerMask);
	
	for ( var i = 0; i < hits.Length; i++)
	{
		var hit : RaycastHit = hits*;*
  •  hit.collider.renderer.enabled = true;*
    
  •  hit.collider.gameObject.renderer.material = gridColor;*
    
  • }*
    }
    The layerMask was set to only collide with the tiles, so it didn’t change anything but tiles.
    Here is what we have so far with a CheckSphere
    var layerMask = 1 << 10;

  • if ( Physics.CheckSphere(transform.position, moveRange, layerMask) )*

  • {*

  • }*
    In the original, we affected the GameObjects that the Ray hit by using a Raycasthit. We have no idea how to do so with a CheckSphere.
    Any help is appreciated, or if anyone has a better method of achiving our goals that we be appreciated as well.

You can use SphereCastAll() or CapsuleCastAll():

RaycastHit[] hits = Physics.SphereCastAll(transform.position, radius, Vector3.forward, 0.001f);

When I last tried, it failed if the distance (last parameter) was 0.0.

function SphereTest ()
{
var gos : GameObject;
gos = GameObject.FindGameObjectsWithTag(“Tiles”);

	for ( var go : GameObject in gos)
	{
		var thisTrans = transform.position;
		var goTrans = go.transform.position;
		var hits : RaycastHit[];
		var layerMask = 1 << 10;
		
		hits = Physics.SphereCastAll(thisTrans, a, Vector3(1,0,1), 0.1);

   		for (var i = 0;i < hits.Length;i++) 
    	{
        	var hit : RaycastHit = hits*;*
  • var renderer = hit.collider.renderer;*

  •  if (renderer)* 
    
  •  {*
    
  •  	renderer.material.shader = Shader.Find("Transparent/Diffuse");*
    
  •  renderer.material.color.a = 0.3;*
    
  •  }*
    
  • }*
    This is a reply to a poster. I didn’t know how else to reply with code and a screenshot. The problem is, the “sphere” doesn’t seem to be a sphere, and nothing I do makes it so. Maybe I’m just not understanding the concept, but to me, Casting a Sphere means casting a Sphere(circle) from the transform.position of my player(where this script is attached) and then returning the tiles it hits, and then rendering those transparent. It seems to be doing… I don’t know. I’ve tried every possible solution to make sense of it. I want to make a circle around my player’s position, and any of the tile’s collider that are within that sphere’s range, I want it to highlight them blue.
    In the Screenshot, my Player Character is the Cube that is off to itself. The Cubes in the middle are currently just Cubes, nothing more.
    [8543-1.png|8543]*