I’m trying to access an array of gameobjects with the same tag (since that seems faster than findobjectsoftype) with the same script attached and change a bool on the script. The amount of objects changes often, which might be of help to know.
The only error in the console I get is this, which I’m still trying to make sense of. “IndexOutOfRangeException: Array index is out of range.
(wrapper stelemref) object:stelemref (object,intptr,object)
Car Rewind.Rewind () (at Assets/Custom Assets/Scripts/Car Rewind.js:31)
Car Rewind.Update () (at Assets/Custom Assets/Scripts/Car Rewind.js:12)”
and here is the script.
import UnityStandardAssets.Utility;
var hasSearched : boolean = false;
var RotaterScript : UnityStandardAssets.Utility.AutoMoveAndRotate[];
var rotaters : GameObject[];
var HubRewindScript : Rewind;
var i : int;
function Update(){
if(HubRewindScript.Reverse == true){
if(!hasSearched){
Search();
Rewind();
}
}
else if(HubRewindScript.Reverse == false){
if(hasSearched){
UnRewind();
hasSearched = false;
}
}
}
function Search(){
rotaters = GameObject.FindGameObjectsWithTag("Enemy");
hasSearched = true;
}
function Rewind(){
for(i = 0; i < rotaters.Length; i++){
RotaterScript _= rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();*_
RotaterScript*.m_reverse = true;
_}
}*_
function UnRewind(){
for(i = 0; i < rotaters.Length; i++){
RotaterScript = rotaters*.GetComponent.<UnityStandardAssets.Utility.AutoMoveAndRotate>();*
RotaterScript*.m_reverse = false;
_}
}*_