Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 cyangamer 1 · Jul 14, 2010 at 08:33 AM · instantiateprefabguitextureguitext

GUITextures not lining up correctly

I'm making an Action RPG. Weird thing happening when my model's Transform is changing (meaning: while it's moving around). When my player gets within a certain radius of this model, a "panel" of sorts slides in from the left side of the screen showing its stats (it's name and health). While the model is stationary, everything looks fine, but when the model is moving, sometimes the different GUITextures that make up the panel don't line up correctly. Why? Because the Game Object that displays these GUITextures is rotated for some reason! Below is my functon:

void OnTriggerEnter(Collider e)
{
    if (e.gameObject.CompareTag("Player") && EnemyYPosition.getEnemyCount() < 4)
    {
        attacker = e.gameObject.GetComponent<Transform>();
        ep = (Transform)Instantiate(ePanel, Vector3.zero, transform.rotation);
        ep.Find("Name").guiText.text = gameObject.name;
        players.Add(e.gameObject);
    }
}

"ep" is the panel Prefab which has a GUITexture component. It also has two children: an object with just a GUIText (that displays the model's name), and another object with a GUITexture (which displays a gradient bar of variable length called the health bar). Since they're all group as one object, they should all move together, but when my model's movement script is activated, sometimes the different child object end up in different positions. Here are the relevant functions in the script attached to the panel object:

IEnumerator Start() { gameObject.transform.position = lossPos; time1 = Time.time; time2 = 0.0f; StartCoroutine(Translation(transform, newPos, 1.0f, MoveType.Time)); while (true) { g.pixelInset = new Rect(g.pixelInset.x, g.pixelInset.y, xHP * guiHP, g.pixelInset.height); //StartCoroutine(EnemyPanelPosition()); yield return null; } }

IEnumerator Translation (Transform thisTransform, Vector3 endPos, float value, MoveType moveType) { StartCoroutine(Translation(thisTransform, thisTransform.position, endPos, value, moveType)); yield return null; }

IEnumerator Translation (Transform thisTransform, Vector3 startPos, Vector3 endPos, float value, MoveType moveType) { float rate = (moveType == MoveType.Time)? 1.0f/value : 1.0f/Vector3.Distance(startPos, endPos) value; float t = 0.0f; while (t < 1.0f) { t += Time.deltaTime rate; thisTransform.position = Vector3.Lerp(startPos, endPos, t); yield return null; } }

If anyone can help, that would be great.

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

2 Replies

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

Answer by cyangamer 1 · Jul 15, 2010 at 06:31 AM

I've now fixed it by putting this command in the Start() method:

gameObject.transform.eulerAngles = Vector3.zero;

Now, the object will always face the same direction when instantiated!

Comment
Add comment · 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 Mike 3 · Jul 15, 2010 at 08:50 AM 2
Share

In that case, you could try something else ins$$anonymous$$d - change the last parameter of the instantiation to Quaternion.identity (And try to always use Quaternion.identity ins$$anonymous$$d of eulerAngles = Vector3.zero )

avatar image
1

Answer by Mike 3 · Jul 14, 2010 at 09:30 AM

Add this after the while loop:

thisTransform.position = endPos;

You were only setting the position to the value of t before it hit 1

Comment
Add comment · 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 cyangamer 1 · Jul 15, 2010 at 06:21 AM 0
Share

Thanks. This may have inadvertently fixed something else, but it didn't fix my problem. After running some more tests, I have figured out what the problem is. I will alter my question shortly to reflect what the actual problem is, because I still don't know how to fix it.

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

No one has followed this question yet.

Related Questions

Multiplying GUIs 0 Answers

Instantiate a 2d Pop up 1 Answer

Instantiating guiText / guiTexture 1 Answer

setting the text of an instantiated prefab's child's guitext object 1 Answer

C#, How do I make the GUIText Show up if Instantiate from a prefab. 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