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 uanmanarmy · Aug 12, 2014 at 01:35 PM · c#newtransforms

Why is not assigning new value ?

     [HideInInspector]
     public Vector3 blueScale;
     [HideInInspector]
     public Vector3 orangeScale;
     [HideInInspector]
     public Vector3 yellowScale;
     [HideInInspector]
     public Vector3 purpleScale;
     [HideInInspector]
     public Vector3 greenScale;
     [HideInInspector]
     public Vector3 redScale;
    
    
     public float blueEnergy;
     public float greeEnergy;
     public float orangeEnergy;
     public float purpleEnergy;
     public float redEnergy;
     public float yellowEnergy;
    
    
     [HideInInspector]
     public  Transform blue;
     [HideInInspector]
     public  Transform green;
     [HideInInspector]
     public  Transform orange;
     [HideInInspector]
     public  Transform purple;
     [HideInInspector]
     public  Transform red;
     [HideInInspector]
     public  Transform yellow;
    
     public   GameObject _blue;
     public  GameObject _green;
     public  GameObject _orange;
     public  GameObject _purple;
     public  GameObject _red;
     public  GameObject _yellow;
  
  
     public Transform FindChild(  GameObject parent, string name)
     {
         if (parent.name == name)
         {
             Debug.Log("Parent's Name is same as you are searching for");
             return null;
         }
  
         Transform pTransform = parent.GetComponent<Transform> ();
         foreach (Transform t in pTransform)
         {
             if (t.name == name)
             {
                 return t;
             }
         }
         return null;
     }
  
  
     public void WhenYouDoSomething(GameObject item, Transform itemTransforms, Vector3 itemScale)
     {
         Debug.Log ("This is when");
         if (item == null)
             Debug.Log ("Item is null");
         else
         {
             itemTransforms = FindChild ( item, "line");
             itemScale = itemTransforms.localScale;
         }
         Debug.Log (itemTransforms);
     }
  
     public void FindItemsObjects()
     {
         _blue = GameObject.FindWithTag ("Blue");
         Debug.Log (_blue);
         WhenYouDoSomething (_blue, blue, blueScale);
         Debug.Log (blue);
  
         _green = GameObject.FindWithTag ("Green");
         WhenYouDoSomething (_green, green, greenScale);
  
         _orange = GameObject.FindWithTag ("Orange");
         WhenYouDoSomething (_orange, orange, orangeScale);
  
         _purple = GameObject.FindWithTag ("Purple");
         WhenYouDoSomething (_purple, purple, purpleScale);
  
         _red = GameObject.FindWithTag ("Red");
         WhenYouDoSomething (_red, red, redScale);
  
         _yellow = GameObject.FindWithTag ("Yellow");
         WhenYouDoSomething (_yellow, yellow, yellowScale);
     }
  
  
 void Start()
     {
         blue = null;
         green = null;
         orange = null;
         purple = null;
         red = null;
         yellow = null;
         FindItemsObjects ();
     }


When I debug.

Debug.Log (blue); it gives me null, but in WhenYouDoSomething function when I debug Debug.Log (itemTransforms); it gives me the object with name line.

Why that transform is not assigned to blue ? or anyotherTransform that I declared?

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

Answer by Chelmney_ · Aug 12, 2014 at 01:42 PM

Hello,

try changing the function declaration to this:

 public void WhenYouDoSomething(GameObject item, out Transform itemTransforms, Vector3 itemScale)

Similarly, you will have to call the function like this:

 WhenYouDoSomething (_blue, out blue, blueScale);

This way you're passing the variable to the function by reference and not by value.

Comment
Add comment · Show 4 · 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 uanmanarmy · Aug 12, 2014 at 01:45 PM 0
Share

The out parameter `itemTransform' must be assigned to before control leaves the current method

this is the error Im getting

avatar image uanmanarmy · Aug 12, 2014 at 01:46 PM 0
Share

k, changing from out to ref, solved the problem THAN$$anonymous$$ YOU!

avatar image Chelmney_ · Aug 12, 2014 at 01:48 PM 0
Share

Add itemTransforms = null in the first if branch like this:

 if (item == null)
 {
     Debug.Log ("Item is null");
     itemTransforms = null;
 }


Variables with out parameters must always be assigned a value in a function and in your version this was not the case because you only assigned it a value in the else branch.

avatar image uanmanarmy · Aug 12, 2014 at 01:55 PM 0
Share

hey, thanks it working like charm :D

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

23 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

Related Questions

New to Unity, Need Help. 1 Answer

Player lives script help 1 Answer

C# -- Build character unit from script 1 Answer

C# Randomly Adding Elements from stringListA to stringListB 1 Answer

C# Input.GetKey("Tab") Double Tap 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