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 Tuah · Jun 23, 2010 at 05:33 AM · charactervariablenamearmatureequip

Comparing similarly-named variables.

I've got one script which references the scripts within two objects.

The script is supposed to take each bone in the first object, change it based on the variable in the script, and then change it again based on a variable of the same name in another script. It then parents the bone of the first object to the same bone of the second object.

This script has been a bit butchered, but it might help visualize a bit.

How can I reference the variables by their names? Or perhaps there is another way to do this?

void tailor(GameObject Equip, GameObject Target) { Equipment equipmentData = Equip.GetComponent<Equipment>(); Character characterData = Target.GetComponent<Character>();

 foreach (Transform bone in Equip) {
     string boneName = bone.name;
     bone.localScale = (bone.localScale / equipmentData.boneName.localScale);
     bone.localScale = (bone.localScale * characterData.boneName.localScale);
     bone.parent = Target.bone;
     bone.localPosition = Vector3.zero;
     bone.localRotation = Target.bone.rotation;
 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Case23 · Jun 23, 2010 at 07:55 AM

If i understand it right, you can simple use a function with if clause like.

public int getSpecificBoneLocalScale (string boneName)
{
     If(boneName.Equals(specificBoneName))
     {
          return specificBone.localScale;
     }
}
Comment
Add comment · Show 2 · 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 Tuah · Jun 23, 2010 at 05:51 PM 0
Share

Ah, so that will refer to a bone of the same name? Is there a way to do it with a variable?

avatar image Case23 · Jun 24, 2010 at 06:23 AM 0
Share

Im not sooo deep into unity till now, and i dont know if bone is a build in thing. But it does not directly refer to the bone with the same name. You check if the string name of the bone equals the string you send. After this you can choose which bone should return. Problem here is, you have to mak an if() for every sepcific Bone.

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

Converting String to Variable Name 3 Answers

String as Variable name 0 Answers

iteration through objects - how can I step through numerically named variables? (or nested / jagged 2D arrays?) 1 Answer

Left-hand side of an assignment must be a variable, property or an indexer 1 Answer

How to Get a Char from his name ? 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