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 jong · Feb 07, 2013 at 09:46 PM · functionguitexturecallcombine

Call GUITexture and script

Help! I have made a GUITexture and a script that will change the texture and I want to call both the GUItexture and its script from another script. Is it possible or is there a way to call both of them or can I call it like this?

example:

quizzes.gameObject.guiTexture.script?

or something like that.

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 phfatmonkey · Feb 08, 2013 at 12:58 AM

Not completely clear what you're asking, but I've found the easiest way to call a script from another script is to assign that object to a public variable, and then use GetComponent to find the script attached to it. Here's an example:

 //this script is attached to your GUITexture
 
 using UnityEngine;
 using System.Collections;
 
 public class GUITextureScript : MonoBehaviour {
 
   public void ChangeTexture ()
   {
      //change texture
   }
 
 }
 
 //this class would be attached to the object from which you want to call/use the GUITexture
 
 using UnityEngine;
 using System.Collections;
 
 public class SomeOtherObjectScript: MonoBehaviour {
   
   public GUITexture guiTx;
 
 
   //then use GetComponent to get the script attached
   private void AMethodThatCallsScriptAttachedToGUITexture ()
   {
      GUITextureScript tex_script = guiTx.GetComponent<GUITextureScript>();
 
     tex_script.ChangeTexture ();
   }
 }

In the Editor just drag the GUITexture object onto the property slot in the script that is attached to the object from which you wish to call the GUITexture script.

Make sense?

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

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

10 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

Related Questions

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

How to call a function in another script 3 Answers

Call a Function from another Script 1 Answer

How can I call a method from another script? 3 Answers

Why can't I call function from another script? 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