Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Mar 07 at 06:20 PM by Zok_Dev for the following reason:

Repost

avatar image
0
Question by Zok_Dev · Mar 07 at 09:08 AM · randomtimereferencinginvokecommunication

Action not triggered after Invoke time passed (Invoke called in different script)

The code should output a random action out of 16 after a editable time. The output should currently only be the random number written in the log but it doesn‘t work. Class 1:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Spawner : MonoBehaviour
 {
     public GameObject thisObject;
     public Funktions funktions;
     // Start is called before the first frame update
     void Start()
     {
         funktions = thisObject.GetComponent<Funktions>();
     }
 
     // Update is called once per frame
     void Update()
     {
         
       funktions.DoOnTickTime();
         
     switch(Funktions.randomNumber)
         {
         case 1:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 2:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 3:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 5:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 6:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 7:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 8:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 9:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 10:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 11:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 12:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 13:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 14:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 15:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         case 16:
         Debug.Log(Funktions.randomNumber);
         Funktions.randomNumber = 0;
         break;
 
         
 
         }
     }
 }

Class2:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System;
 
 public class Funktions : MonoBehaviour
 {   public static float spawnSpeedCount;
     public static int countdownTime = 2;
     public static int randomNumber;
     
         void Start()
         {
             
         }
     //One Tick
     public void OnTick()
     {
         int randomNumber = UnityEngine.Random.Range(1, 17); 
         spawnSpeedCount += 1;
         
     }
     public void DoOnTickTime()
     {if(!IsInvoking("OnTick"))
         {
      Invoke("OnTick", countdownTime);
         }
     }
    
 
     
     
         
 }
 

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

141 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

InvokeRepeating with a variable? 2 Answers

Random time interval 1 Answer

Randomize Spawn Times 0 Answers

Timed event Question 2 Answers

Random.range returning similar values 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