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 Theacesofspades · Dec 13, 2014 at 01:29 AM · c#texturefunctioncall

Why is calling a function wrong?

I have 2 scripts. One with this function:

 public void UpdateTexture (int texture)
     {
         foreach (Transform side in transform)
         {
             side.renderer.material.SetTextureScale("_MainTex", size);
             side.renderer.material.SetTextureOffset("_MainTex", new Vector2(textures[texture].x*size.x, textures[texture].y*size.y));
         }
     }

and another script that is trying to call on that function:

 currentSide.GetComponent<BlockScript>().UpdateTexture(0);

When the first script calls on the function it is correct. But when i call on that function from a different script, the texture is different and wrong. What is going on and how could i fix it? thanks

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

Answer by Kerihobo · Dec 13, 2014 at 07:26 AM

I am GUESSING... I havnt tested this, sue me if it doesn't work.

 currentSide.GetComponent<BlockScript>().UpdateTexture(0);

could probably be:

 BlockScript blockscript = YourGameObject.GetComponent<BlockScript>();

After that you can go:

 blockscript.UpdateTexture(0);
Comment
Add comment · 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
0

Answer by Kiwasi · Dec 13, 2014 at 02:00 AM

As written this script will modify the texture of the GameObject it is on. To have it modify the calling object you must also pass I a reference to that object.

Comment
Add comment · Show 3 · 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 Theacesofspades · Dec 13, 2014 at 05:37 AM 0
Share

Can you explain more please?

avatar image Kiwasi · Dec 13, 2014 at 05:56 AM 2
Share

Not really, you don't have much detail in your question to go on. 'different and wrong' is not a technical term. If you explain yourself clearly we might be able to help. What exactly is happening, and what did you want to happen?

avatar image Theacesofspades · Dec 13, 2014 at 04:43 PM 0
Share

Ins$$anonymous$$d of being grass texture it is black. But when I call the function from its own script it is grass.

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

27 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

Related Questions

How to reference another script and call a function in C# ? 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What is the best way to call a function from another script 1 Answer

How to call a script from an object that is DontDestroyOnLoad 2 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