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 Geads · Nov 11, 2017 at 12:35 AM · scripting problemenemyscript errorduplicatescriptable object

Scrolling combat text works on enemy. When I duplicate and have two enemies I get a problem.

I created scrolling combat text to float over an enemy when they are damaged by a bullet. When I duplicate the enemy everything works fine and I have two perfectly working enemies. The problem is when enemy2 gets hit, it displays the scrolling combat text over enemy1 and when enemy1 gets hit, it also displays the scrolling combat text over enemy1. The share the position of the scrolling combat text some how even though everything else is separate. They act like two individual enemies except for that part.

Comment
Add comment · Show 2
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 ShadyProductions · Nov 11, 2017 at 01:16 AM 1
Share

Please show the code, now there is no way for us to see what the issue is.

avatar image Geads ShadyProductions · Nov 11, 2017 at 01:22 AM 0
Share

I added the relevant code

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Geads · Nov 11, 2017 at 01:22 AM

EnemyCombatTextManager script

 public class EnemyCombatTextManager : MonoBehaviour
 {
 
     public float speed;
 
     public Vector3 direction;
 
    
 
     public static EnemyCombatTextManager instance;
 
     [SerializeField]
     public GameObject textPrefab;
 
     public RectTransform canvasTransform;
 
     public float fadeTime;
 
     public static EnemyCombatTextManager Instance
     {
         get
         {
             if (instance == null)
             {
                 instance = GameObject.FindObjectOfType<EnemyCombatTextManager>();
             }
             return instance;
         }
     }
 
     public void CreateText(Vector3 position, string text, Color color, bool crit)
     {
         GameObject sct = (GameObject)Instantiate(textPrefab, position, Quaternion.identity);
         sct.transform.SetParent(canvasTransform, false);
         sct.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
         sct.GetComponent<CombatText>().Initialize(speed, direction, fadeTime, crit);
         sct.GetComponent<Text>().text = text;
         sct.GetComponent<Text>().color = color;
     }
 }



Where I call it in the enemy script

 EnemyCombatTextManager.Instance.CreateText(transform.position, "-" + enemyrndDmg.ToString(), Color.red, false);
 



It works perfect for a single enemy. Once I duplicate the enemy so there is enemy1 and enemy2, the enemies both work perfect, but the scrolling combat text is only over enemy2 even if enemy 1 or enemy2 is getting damaged

Comment
Add comment · Show 5 · 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 ShadyProductions · Nov 11, 2017 at 01:35 AM 1
Share

public RectTransform canvasTransform; <-- never changes because you grab the same instance. So its likely still on the first enemy?

Perhaps you can pass it as a parameter ins$$anonymous$$d

      public void CreateText(Vector3 position, string text, Color color, bool crit, RectTransform canvasTransform) {
 
 }
avatar image Geads ShadyProductions · Nov 11, 2017 at 02:17 AM 0
Share
 sct.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);

is this what you are referring to? This just sets the scale of the font to 1,1,1.

The text is showing on one canvas ins$$anonymous$$d of each duplicated enemies personal canvas

avatar image ShadyProductions Geads · Nov 12, 2017 at 12:29 PM 1
Share

please re-read my answer.

Show more comments

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

124 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

Related Questions

Respawn Point dont work, is because is a prefab? 2 Answers

How to know exactly which game objects and objects are not referenced ? 1 Answer

Half-issue with find enemy script 1 Answer

Some public methods can not be called 2 Answers

Getting Null Reference Exception on working Script ? 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