I have this script, and it gives me these errors. What is wrong?
Thanks!
Assets/MyClass.cs(9,37): error CS1519: Unexpected symbol `RandomValue’ in class, struct, or interface member declaration
Assets/none.cs(17,17): error CS0178: Invalid rank specifier: expected ,' or ]’
using UnityEngine;
using System.Collections;
public class MyClass : MonoBehaviour {
GameObject[] non;
int i = 0;
InvokeRepeating("Activator", 0.1f, 0.1f);
void Activator() {
i++;
if(i >= non.Length)
{
i = 0;
}
non[!=i].SetActive(false);
}
}
Nice, it fixed the first problem! It is weird, because in Js it doesn't need to be inside a function Do you know why the second problem happens though?
– smirlianos'
– gjf!=i' isn't valid for an array index. did you mean 'i'?To achieve the 'everything else' index you need to use a loop to iterate through the full array. JavaScript allows a lot of lazy things. Eventually it always gets people into trouble. C# is stricter, which causes less headaches in the long term.
– KiwasiYes, I try to achive the everything else. How will I go about creating that loop?
– smirlianosI managed to do this, but it stops after one cycle: #pragma strict var non : GameObject[]; function Change() { for (var x : int = 0; x < non.Length; x++) { non[x].SetActive(true); for(var y : int = 0; y < non.Length; y++) { Debug.Log(x + " " + y); if(y != x) { non[y].SetActive(false); } } if(x >= non.Length) { x = 0; } yield; } } function Update() { Change(); }
– smirlianos