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 JD- · Mar 01, 2011 at 08:12 PM · guitexturetriggerimageanimate

How do I trigger GUI elements

I want an image to fly in from the left screen when I run over a trigger object in my scene, then animate back out to the left when I exit the trigger collider.

Nothing I'm trying is working. The latest thing I've tried is, I have an object with the following script attached.

var showSlideOne : boolean; var showSlideSeven : boolean;

var slide01 : Texture2D; var slide07 : Texture2D;

var position01 : Rect; var position07 : Rect;

function Start () { var CurrentX_01 = 0.0; var CurrentX_07 = 0.0;

 position01 = Rect(CurrentX_01,0,1024,768);
 position07 = Rect(CurrentX_07,0,1024,768);

}

function OnGUI () {

 if (showSlideOne) {
     GUI.DrawTexture( position01, slide01 );
 }
 if (showSlideSeven) {
     GUI.DrawTexture( position07, slide07 );
 }

}

Then I have the following script attached to the collider object.

function OnTriggerEnter (col : Collider) { print("On Ducts");

 showSlideSeven = true;

} function OnTriggerExit (col : Collider) { print("Off Ducts");

 showSlideSeven = false;

}

The trigger doesn't show or hide the images, but the print commands work. Can anyone tell me why, and how to fix the images triggering?

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 Alec-Slayden · Mar 01, 2011 at 09:25 PM

Your showSlideSeven and showSlideOne variables are local to the first script. That means in order to change them in a different script, you'll need to access the other object and then access the script on that object.

By defining the variables as you have it in the second script, They are created on the fly local to those functions, so they're separate and completely unused variables.

If you refer to these variables often throughout all your scripts, you may want to define them as "static var" instead of "var"

Then, if we say the script is called "scriptname", all you have to do is:

scriptname.showSlideOne = true;
Comment
Add comment · Show 1 · 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 JD- · Mar 01, 2011 at 10:14 PM 0
Share

That worked great! Thank you so much!

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

How can I prevent my GUI background texture from getting pixelated or stretched? 1 Answer

Progress Bar Parallel To Game Progress - HELP 1 Answer

Path Trigger Animation 1 Answer

How can I add a distance cap to this script? 3 Answers

How do I change the texture of a Raw image? 0 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