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 peluche · Oct 25, 2011 at 03:16 AM · errorspritespritemanagerspritemanager2

error CS1520: Class, struct, with Sprites

Hi everyone.

Im having a big problem with sprites (SpriteManager http://www.anbsoft.com/middleware/sm2/) and Unity...

I have this code:

using UnityEngine; using System.Collections;

public class QuestItemsSpriteController : MonoBehaviour {

  Update () {
     StartDelay();
         Sprite.PlayAnim(0);
     StartDelay();
         Sprite.PlayAnim(1);
     StartDelay();
         Sprite.PlayAnim(2);
 }
 
 IEnumerator StartDelay(){
     yield return StartCoroutine(WaitSeconds (3.0f));
 }
 
  IEnumerator WaitSeconds (float delay) {
     float timer = Time.time + delay;
     while (Time.time < timer) {
         yield return null;
     }
 }

}

But the compiler send me this error message:

error CS1520: Class, struct, or interface method must have a return type

Any solution???

Thx

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · Oct 25, 2011 at 03:31 AM

Simple- you need to add the word 'void' before Update(), to declare that it doesn't have a return type! (I know, it seems kind of counter-intuitive, but that's just the way it works.)

 void Update()
 {
     // code goes here, gets run once a frame.
 }

Of course, since you are planning to use IEnumerators inside of your start function, you probably want to use it like this, instead:

  IEnumerator Start () {
     yield return StartDelay();
     Sprite.PlayAnim(0);
     yield return StartDelay();
     Sprite.PlayAnim(1);
     yield return StartDelay();
     Sprite.PlayAnim(2);
 }

Unless you want every frame to last for 9 seconds, you shouldn't put delays inside of Update! If you use Start as an IEnumerator, that will all execute properly on the first frame, however if you instead want it to trigger when you meet some condition, make all of that into a separate Coroutine, by changing the name of it from Start to something else, like 'PlaySpriteAnims', and then calling

 StartCoroutine(PlaySpriteAnims());

when you want it to start.

One other thing, you see that lovingly written bit of code 'WaitSeconds'? There is an inbuilt function which does exactly that, called WaitForSeconds(float seconds)- you use it where you would have had

 yield return StartCoroutine(WaitSeconds (3.0f));

by putting

 yield return new WaitForSeconds(3.0f);

instead. I'm honestly not sure whether it'd be faster or not- but a good rule of thumb is to use inbuilt functions whenever you have the choice.

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

Answer by peluche · Oct 25, 2011 at 10:20 PM

Ok, I did these changes.

And have the code like this.

using UnityEngine; using System.Collections;

public class QuestItemsSpriteController : MonoBehaviour {

 void Start(){
     
     StartCoroutine(PlaySpriteAnims());
 }
 
 
  IEnumerator PlaySpriteAnims () {
      yield return new WaitForSeconds(3.0f);
      Sprite.PlayAnim(0);
      yield return new WaitForSeconds(3.0f);
      Sprite.PlayAnim(1);
      yield return new WaitForSeconds(3.0f);
      Sprite.PlayAnim(2);
 }
 

}

And have this error:

error CS0120: An object reference is required to access non-static member `Sprite.PlayAnim(UVAnimation_Multi)'

Options?

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 syclamoth · Oct 25, 2011 at 11:32 PM 0
Share

Well, presumably you are using some kind of sprite-manager- this error suggest that you need an instance of the Sprite class to be able to do your work! Look up your sprite manager documentation, since I really have no idea how your specific system works. From the sounds of the error, you need something like

 public Sprite mySprite;

at the top, and then you need to replace all your references to Sprite with references to mySprite.

But, as I said, I don't know how this library works, so you'll just have to check your documentation.

avatar image
0

Answer by peluche · Oct 26, 2011 at 10:46 PM

Thx.

I chaged my algorithm and put the script in another object and assign the object who has the spritemanager and works :D

But I will check the documentation to know more about this error.

Greetings

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Changing sprite properties at runtime 2 Answers

The name 'PackedSprite' does not denote a valid type ('not found') 3 Answers

SpriteManager 2 pixel perfect blurry and stretched 2 Answers

iOS SpriteManager 2 issue with backgrounds 1 Answer

How do I use the PlayAnim function in SpriteManager 2? 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