Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Enyph-Games · Jan 25, 2016 at 03:55 PM · c#canvasplaymode

Text shows only when i exit playmode?

I am making an infinite runner game, and player is able to collect coins. This is my script attached to the coins:

using UnityEngine; using System.Collections;

public class PickUpScript : MonoBehaviour { public GameObject MoneyText;

 void Update()
 {
     transform.Rotate (new Vector3 (0, 30, 0) * Time.deltaTime);
 }
 
 void OnTriggerEnter(Collider other) 
 {
     Debug.Log ("pick up picked up");
     MoneyText.GetComponent<MoneyScript>().PickedUp ();
     gameObject.SetActive (false);
 }

}

And this is my script attached to MoneyText GameObject:

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class MoneyScript : MonoBehaviour { public float money; public Text moneyText;

 public void PickedUp()
 {
     Debug.Log ("asd");
     money = money + 1;
     SetMoneyText ();
 }

 void SetMoneyText()
 {
     moneyText.text = "Money: " + money.ToString ();
 }

}

Ok, those are really simple scripts, but that float money doesn't increase during playmode, it increases when i exit playmode. I want it to increase during playmode, and i don't get what could be the problem here. :)

Thanks :)

Comment
Add comment · Show 5
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 Enyph-Games · Jan 25, 2016 at 02:33 PM 1
Share

$$anonymous$$aybe it might have to do something with that the $$anonymous$$oneyText gameobject is also a prefab?

avatar image Garazbolg Enyph-Games · Jan 25, 2016 at 04:21 PM 0
Share

It depends, did you instanciated it in the Scene ? And did you reference the Text GameObject in the moneyText field ?

Forget about the prefab for now just use a GameObject in your scene, and then -when it works- add it to your project as a prefab.

avatar image Enyph-Games Garazbolg · Jan 25, 2016 at 04:45 PM 0
Share

I didn't instantiate it. And i did reference it. But i solved the problem :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Enyph-Games · Jan 25, 2016 at 07:23 PM

I solved the problem myself. If someone wants to know what was the problem, it was that, because moneyText was public, i had to assign it in the inspector, and i assigned the prefab. So, when i played the values did change, but not in the MoneyText gameobject, they changed in MoneyText prefab, and then when i exit playmode, the gameobject takes the values from the prefab. Bye :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Why does RectTransform.position ignore the scaleFactor of the canvas? 0 Answers

When I pop-up the Canvas using keyboard, That code doesn't operate.(Unity 5) 0 Answers

All compiler errors have to be fixed, but no errors? 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