# array help needed

**URL:** https://discussions.unity.com/t/array-help-needed/396425
**Category:** Camera
**Tags:** Scripting
**Created:** [August 13, 2009, 11:22pm UTC](https://discussions.unity.com/t/array-help-needed/396425 "2009-08-13T23:22:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_24297983](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon\_24297983](https://discussions.unity.com/u/anon_24297983)
#### Post date: [August 13, 2009, 11:22pm UTC](https://discussions.unity.com/t/array-help-needed/396425/1 "2009-08-13T23:22:20Z")

</div>

Hi I am trying to make a array of all the cameras in the scene that are within a certain distance from the caller.

I just started programing and am not too confidant with arrays yet.

```auto
var cameraRange = 30;
var viewList[] = new Array ();
var numbInRange : int;

function Update () {
	var cameras[] = Camera.allCameras;
	for (var camera : Camera in cameras[])
    {
		if (Vector3.Distance(transform.position, camera.position) >= cameraRange) {
		numbInRange++;
		}
		else {
			
		}
	}
}

```

---

<div class="post-metadata">

### Author: ![matthewminer](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/matthewminer/32/430918_2.png) [@matthewminer](https://discussions.unity.com/u/matthewminer)
#### Post date: [August 14, 2009, 12:20am UTC](https://discussions.unity.com/t/array-help-needed/396425/2 "2009-08-14T00:20:30Z")

</div>

That’s a good start. A few things:

- The \>= operator should be \<=, unless you’re trying to find cameras that are _outside_ the given range
- Instead of keeping track of how many cameras there are with the numbInRange variable, just add the camera itself to the array (see the next point)
- Instead of using a built-in array, use an [Array](http://unity3d.com/support/documentation/ScriptReference/Array.html) object; this will allow you to keep adding items without first setting a specific size
- To get the camera’s position, use camera.transform.position; a camera position doesn’t have a position variable, but its transform does
