Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by smirlianos · Jul 18, 2014 at 11:23 AM · errorinvokeinvokerepeatingrepeating

InvokeRepeating doesn't work

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);
     }
 }








Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiwasi · Jul 18, 2014 at 11:31 AM

Invoke repeating is a method, and must be called from within a method or property. Try moving it into start.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smirlianos · Jul 18, 2014 at 11:34 AM 0
Share

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?

avatar image gjf · Jul 18, 2014 at 11:37 AM 0
Share

'!=i' isn't valid for an array index. did you mean '`i`'?

avatar image Kiwasi · Jul 18, 2014 at 11:39 AM 0
Share

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.

avatar image smirlianos · Jul 18, 2014 at 11:43 AM 0
Share

Yes, I try to achive the everything else. How will I go about creating that loop?

avatar image smirlianos · Jul 18, 2014 at 12:49 PM 0
Share

I 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();
 }
Show more comments
avatar image
0

Answer by gjf · Jul 18, 2014 at 01:02 PM

maybe something like this would work for you:

 public GameObject[] non;
 private int index = 0;

 void Update()
 {
     Change();
 }

 private void Change()
 {
     index++;
 
     if (index >= non.Length)
     {
         index = 0;
     }
 
     for (var i = 0; i < non.Length; i++)
     {
         non[i].SetActive(i == index);
     }
 }

this is c# - the second piece of code you posted is unityscript, whereas the first was c#.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Invoke.Repeating doesn't really "care" about repeat time? 1 Answer

Is it possible to change Invoke Repeating rate on the fly? 3 Answers

Subtract one from health every five seconds. 1 Answer

InvokeRepeating affecting parts of script 1 Answer

HELP BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Vector3'. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges