• 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
Question by GesterX · Apr 07, 2011 at 09:01 PM · coroutineitween3dtext

Why won't my coroutine start?

I have a script which uses iTween to display experience gained from an enemy which is kicked off by a health script attached to the enemy. Here are the relevant parts of the script:

EnemyHealth.js attached to enemy - this happens upon death

var aRotation = Quaternion.Euler(0 , 0 , 0); Instantiate(xpText, transform.position, aRotation); print(myExpText); xpText.GetComponent(XPText).ChangeText(myExpText); xpText.GetComponent(XPText).DisplayXP();

 Network.Destroy(gameObject);

XPText.js (attached to a 3DText prefab called XPText)

function DisplayXP() {

 yield WaitForSeconds(1);
 print(textContent);
 GetComponent(TextMesh).text = textContent;
 iTween.FadeTo(gameObject, 1, 0.5);
 yield WaitForSeconds(2);
 iTween.FadeTo(gameObject, 0, 0.5);

 yield WaitForSeconds(1);
 Destroy(gameObject);

}

function ChangeText(valueA) { textContent = valueA.ToString() + "XP"; }

Please note that Network.Instantiate is intentional.

When I kill an enemy I get the following error:

"Coroutine couldn't be started because the the game object 'XPText' is inactive!"

So I removed the "yield WaitForSeconds" lines but then I get the error:

Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy(Object)

Any ideas how what I've done wrong or any way around this?

Comment

People who like this

0 Show 0
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
Best Answer

Answer by Mike 3 · Apr 07, 2011 at 10:11 PM

You're trying to start the coroutine on the prefab, not the instantiated object

Try something like this:

var instantiated = Instantiate(xpText, transform.position, aRotation);
print(myExpText);
instantiated.GetComponent(XPText).ChangeText(myExpText);
instantiated.GetComponent(XPText).DisplayXP();
Comment
GesterX

People who like this

1 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 GesterX · Apr 07, 2011 at 10:16 PM 0
Share

Spot on! Thanks!

avatar image

Answer by DaveA · Apr 07, 2011 at 09:39 PM

Just a quick thought: If the XPText it refers to is on this line:

Instantiate(xpText, transform.position, aRotation);

then make sure xpText is active by either setting .active = true or checking the box on it in the Inspector.

Comment

People who like this

0 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 GesterX · Apr 07, 2011 at 09:55 PM 0
Share

When I add xpText.gameObject.active = true; I get an error saying: "Prefab GameObject's can not be made active! (XPText)". xpText is a Prefab for a 3DText GameObject with the XPText script attached to it. Basically when the enemy dies I want it to instantiate the 3DText with a fade effect (hence iTween).

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

iTween ValueTo onupdateparam help 1 Answer

Confused about using Update vs. Coroutines 2 Answers

Get a "Another coroutine is already waiting for" log... Why? 1 Answer

how to restart coroutine on event? 2 Answers

In Unity 4.1 www.isDone doesn't seem to work in Android. Any suggestion? 0 Answers


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