• 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 Rembo4Fight · Feb 18, 2018 at 09:41 AM · scripting problemvector2positioning

Put the text on Collectibles position !

Hi, I tried to make it about a week, and nothing helps on my own.

So I'm making a 2D game, where the player collecting collectibles, and I want to make the text appearing on the position where was the collectibles item.

So I added spawnX and spawnY variable to my Collectibles script to know the position of collectible item.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Collectibles : MonoBehaviour {
 
     public int scoreValue;
 
     public bool alreadyScored;
 
     public float spawnX, spawnY;
 
     void Start()
     {
         spawnX = transform.position.x;
         spawnY = transform.position.y;
     }
 
     void OnTriggerEnter2D (Collider2D col) {
         if (col.gameObject.layer == LayerMask.NameToLayer ("Player")) {
 
             if (alreadyScored)
                 return;
             alreadyScored = true;
 
             ScoreManager.score += scoreValue;
             ScoreManager.collected = true;
 
         } else {
             ScoreManager.collected = false;
         }
     }
 }

And created the ScoreManager script, which is collecting all the data.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
 
 public class ScoreManager : MonoBehaviour {
 
     Animator anim;
 
     public static int score;
 
     private float m_smoothScore;
     private float m_smoothScoreVelocity;
     private int m_displayedScore = -1;
 
     TextMeshProUGUI TMPtext;
 
     public static bool collected;
 
     public float min;
     public float max;
     public float t;
 
     void Awake()
     {
         TMPtext = GetComponent<TextMeshProUGUI> ();
         score = 0;
     }
 
     void Start()
     {
         anim = GetComponent<Animator> ();
         collected = false;
     }
 
     void Update () {
         //smooth score animation
         m_smoothScore = Mathf.SmoothDamp(m_smoothScore,(float)score,ref m_smoothScoreVelocity, 0.2f, Mathf.Infinity, Time.deltaTime * 1.2f);
 
         //display the text
         int toDisplay = (int)Mathf.Round(m_smoothScore);
         if (toDisplay != m_displayedScore) 
         {
             m_displayedScore = toDisplay;
             TMPtext.text = toDisplay + " PTS";
         }
 
         if (score > 0) 
         {
             anim.SetBool ("Points", true);
         }
         if (collected == true) {
             t = Time.time;
             TMPtext.fontSize = Mathf.Lerp (min, max, t);
             collected = false;
         } else {
             t = Time.time;
             TMPtext.fontSize = Mathf.Lerp (max, min, t);
         }
     } 
 }

So what exactly I need to make to have the (prefab) text, which will be appearing on the position of the collectible item. I know that collectible item will be destroy, but spawnX and spawnY will send the info about positioning sooner then it will be destroyed.

Thank you if you read this all, I hope this will resolve. :)

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

133 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 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

How can I launch a ball given an angle in degrees and a magnitude? 2 Answers

Why does this code not work? 1 Answer

Sync an Object's X-axis location to another Object's specific Frame Animation. 0 Answers

How to implement listeners in unity3d android plugin? 0 Answers

Why doesn't my object move left? 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