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 /
This question was closed May 19, 2013 at 08:56 PM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by sdgd · May 19, 2013 at 12:01 PM · c#waitforsecondsinvokestruct

Invoke on Struct or some else time wait

 using UnityEngine;
 using System.Collections;
 
 public struct SomeStruct {
     public void example (){
         Invoke("example1",2);
     }
     void example1 (){
         Debug.Log("asdgsfdgjhsdfgj");
     }
 }

I get an error: Assets/Email.cs(6,17): error CS0103: The name `Invoke' does not exist in the current context

but if I do same thing in class monobehaviour I have no problems whatsoever

is there any possibility to do this in structure?

as I've found out that invoke works in update and in start so I do not understand why can't it work in structure

but if I'd do it this way:

 using UnityEngine;
 using System.Collections;
 
 public struct SomeStruct {
     public IEnumerator Example() {
         Debug.Log(""+Time.time);
         yield return new WaitForSeconds(1);
         Debug.Log(""+Time.time);
     }
     public void Example1(){
         Debug.Log(""+Time.time);
     }
 }

and if I call example I get nothing at all

and if I call example 1 I get normal debug as I should

and OFC I'm calling it from start

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Ashkan_gc · May 19, 2013 at 12:15 PM

Well it's because Invoke is a member of MonoBehaviour class and only classes derived from it can call it, So you can not call Invoke in a struct. read about OO concepts and inheritance in a book or on the web to know more about it.

Simulating the functionality is possible using reflection and members of the system.reflection namespace but it's a little harder to do. There was a unite talk on reflection and the book programming C# 3 by j.liberty describes it as well. Take a look if you are interested. Basically you get the type of an object using GetType() method or typeof() operator and the using reflection get MethodInfo object of the method that you want by passing it's name and then you can call/invoke that methodInfo.

Comment
Add comment · Show 1 · 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 sdgd · May 19, 2013 at 12:21 PM 0
Share

ok thanks for your effort :)

while playing some more I've figured out I can't do it with invoke as you said so I went looking in to yield some more and I figured out why didn't it work

well because I was only calling the function Example While I should Call it

 StartCoroutine(Em.Example());

and when I did that both ways worked Start and update :)

so thanks for your effort even if it wasn't totally right answer but it did pushed me in to the right way :)

Follow this Question

Answers Answers and Comments

14 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

Related Questions

I have a button with a cooldown. How do I make it so the cooldown time increases with each press of the button? 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

Convert this Javascript into C#? 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