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 Smurfj3 · Feb 15, 2015 at 09:11 PM · scripting problemtransformparentscriptingbasicsparenting

Parent mesh problem

I made a video to show what excacly happens. You can see me dragging the 2 weapons into the hierarchy, they appear in the scene. Then when I click on the play button, I show you where the 2 weapons are located at the beginning of the game and I show you what happens if I scroll down. When I scroll down the Axe scales way down but stays at the same position.

Click here for Video here

Here follows the code:

 #pragma strict
 
 public var weapons : GameObject[];
 
 private var currentw : int;
 private var nmrweapons : int;
 private var weaponslot : Transform;
 
 
 
 function Start () {
 
 weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");
 weapons = GameObject.FindGameObjectsWithTag("Weapon");
 currentw = 0;
 nmrweapons = weapons.Length;
 Debug.Log("test");
 }
 
 function Update () {
 
 if(Input.GetAxis("Mouse ScrollWheel")<0) {
 
     if(currentw == nmrweapons){
     currentw = 0;
     }
     else{
     currentw = 1;
     }
     Debug.Log("test1");
     Changeweapon(currentw);
     
     }
 }
 
 function Changeweapon(cw:int){
 
 Debug.Log("test3");
 weapons[cw].transform.parent = weaponslot;
 weapons[cw].transform.localPosition = Vector3.zero;
 weapons[cw].transform.localRotation = Quaternion.identity;
 weapons[cw].transform.localScale = Vector3.one;
 
 }

I really do not understand anymore what to do, I've tried loads of things. But I just do not have enough knowledge of coding, so I really do need someone to explain me, why its doing what its doing. I am still new at coding so it's probably a dumb mistake.

Thanks in advance

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
1
Best Answer

Answer by giulio-pierucci · Feb 15, 2015 at 11:40 PM

The row:

  weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");
 

fails, because the name is wrong ( ...@Idle/malemodel/...) then weaponslot is null

this row:

 weapons[cw].transform.parent = weaponslot;
 


is weapons[cw].transform.parent = null;

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 Smurfj3 · Feb 16, 2015 at 12:47 PM 0
Share

I understand that weapons[cw].transform.parent = null < I understand that part but what is wrong about:

weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");

That are the excact names as they are in the hierarchy literally copied. You mean it has to be: weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/null"); ?

avatar image Smurfj3 · Feb 17, 2015 at 01:19 AM 0
Share

Problem is solved already there was some other mistakes other then the one you told me that I didn't see -.- thanks for that!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to instantiate a GameObject in a scene and keep world transform? 3 Answers

Child object getting transformed out side the scene on collision? 1 Answer

Trying to make an object "Flee" from the player but it won't work? 3 Answers

Rotation drift with transform.eulerAngles 0 Answers

Parenting Transforms, Must (still) Set Parent at 0,0,0 ? 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