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 nzmichael118 · Sep 17, 2017 at 10:00 PM · prefabtextscore

Code Not working

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Size_Changer : MonoBehaviour
 {
     public Vector3 maxLocalScale;
     float maxlocalScaleMagnitude;
     public Text CountText;
 
     void Start()
     {
 
         maxLocalScale = new Vector3(0.1F, 1, 0.1F);
         maxlocalScaleMagnitude = maxLocalScale.magnitude;
         CountText = GameObject.Find("CountTextObject"); // No work line
     }
 
 
     void LateUpdate()
     {
 
         float actualLocalScaleMagnitude = transform.localScale.magnitude;
         if (actualLocalScaleMagnitude < maxlocalScaleMagnitude)
         {
 
             transform.localScale += new Vector3(0.0005F, 0.001F, 0.0005F);
         }
 
         else
         {
             Score1.score++;
             print("your score is now:" + Score1.score);
             Destroy(gameObject);
             CountText.text = Score1.score.ToString ();
 
 
         }
     }
 }

// Assets/Scripts/Size_Changer.cs(17,32): error CS0029: Cannot implicitly convert type //`UnityEngine.GameObject' to `UnityEngine.UI.Text'

Comment
Add comment · Show 1
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 MT369MT · Sep 18, 2017 at 05:40 AM 0
Share

Hi. Try to use this: CountText = GameObject.Find("CountTextObject").GetComponent();

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by tormentoarmagedoom · Sep 18, 2017 at 09:50 AM

Good day @nzmichael118 !

In line 10 you defined CounText as a Text component

  public Text CountText;

But at line 17, you are looking for a gameobject called CountText, but Countext is not an object, is a component Text from some object

 CountText = GameObject.Find("CountTextObject");

So, you should define Countextxt as text component of the object:

 CountText = GameObject.Find("CountTextObject").GetComponent<Text>();

So now, yes, CountText.text can be edited with

 CountText.text = Score1.score.ToString ();

If this post helps, mark as good and upvote!

If need more help, just ask using @tormentoarmagedoom

Bye :D !

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

91 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

Related Questions

Why can't I drag text into public text in the inspector when instantiated? 1 Answer

UI Text.color not assigning? 2 Answers

Modified Roll a Ball Tutorial,Modified Roll a Ball tutorial question 1 Answer

Display text above prefabs in Unity 4.6 0 Answers

Which type of Variable do I need to use to change the Value of a text UI object ? 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