I keep getting this error. Argument is out of range. What does it mean?
Here is the code:
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts.Player
{
public class CameraScript : MonoBehaviour
{
Bounds b;
private new Transform transform;
private Vector3 DesiredPos;
public List<Transform> Players;
public float camSpeed;
private Camera cam;
public List <Transform> UpdatePlayers;
void Awake ()
{
transform = GetComponent<Transform>();
cam = GetComponent <Camera> ();
}
public void Start ()
{
b = new Bounds(new Vector2(0f, 0f), new Vector2(12f, 8f));
var p = GameObject.FindGameObjectsWithTag ("Player");
Players = new List<Transform> ();
for (int i = 0; i < p.Length; i++)
{
Players.Add(p*.GetComponent<Transform>());*
-
}*
-
}*
-
void Update ()*
-
{*
-
if (Players.Count <= 0)*
-
{*
-
return;*
-
}*
-
DesiredPos = Vector3.zero;*
-
float distance = 0f;*
-
var hSort = Players.OrderByDescending (p => p.position.y);*
-
var wSort = Players.OrderByDescending (p => p.position.x);*
-
var mHeight = hSort.First ().position.y - hSort.Last ().position.y;*
-
var mWidth = wSort.First ().position.x - wSort.Last ().position.x;*
_ var distanceH = -(mHeight + 5f) * 0.5f / Mathf.Tan (cam.fieldOfView * 0.5f * Mathf.Deg2Rad);_
_ var distanceW = -(mWidth / cam.aspect + 5f) * 0.5f / Mathf.Tan (cam.fieldOfView * 0.5f * Mathf.Deg2Rad);_
-
distance = distanceH < distanceW ? distanceH : distanceW;*
-
for (int i = 0; i < Players.Count; i++)*
-
{*
_ DesiredPos += Players .position;_
* }*
* if (distance > -10f)*
* distance = -10f;*
* DesiredPos /= Players.Count;*
* DesiredPos.z = distance;*
* var k = GameObject.FindGameObjectsWithTag (“Player”);*
* for (int l = 0;l < k.Length; l++)*
* {*
* if (b.Contains (k [l].transform.position))*
* {*
* Players.Add (k [l].GetComponent());*
* }*
* else*
* {*
* Players.RemoveAt(l);*
* }*
* }*
* }*
* void LateUpdate ()*
* {*
* transform.position = Vector3.MoveTowards (transform.position, DesiredPos, camSpeed);*
* }*
* }*
}
Copied it from the internet and tried to adapt it to my game.