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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Marvin Hawkins · May 17, 2012 at 01:02 PM · guivariableshealth

How to display gui.texture from a different script

I'm trying to do a simple player lives/powerups/whatever display using Unity textures. I want to create one GUI script that takes the variables from other scripts. I was able to succesffuly create a health bar using this method, but I'm hung up on grabbing a variable (player teddypowerup) and displaying it using the other script. Here's what I have so far, where am I going wrong?

1) Create a Gui gameobject and attach this script:

var TeddyTexture : Texture2D;

function Update () { guiTexture.texture = TeddyTexturGamecontroller.PowerUpTeddy]; }

//@script ExecuteInEditMode It's grabbing the variable 'PowerUpTeddy' from the GameController script

var player : GameObject; //var guiSkin : GUISkin; var spawnPoint : Transform; public var mainCam : Camera; public var StartSpawn : boolean=true; var pos : Vector2 = new Vector2(20,40); var size : Vector2 = new Vector2(60,20);

static var PowerUpTeddy = 1; static var Costume = 0;

function Awake() { if(!spawnPoint){spawnPoint= transform;} if(!mainCam){mainCam=Camera.main;} if(StartSpawn){ var curPlayer:GameObject=Instantiate(player, spawnPoint.position, transform.rotation); } mainCam.gameObject.GetComponent(cam).target =curPlayer; var PowerUpTeddy = 1; } The following code generates a "Array out of scope error" even if I instantiate the script to '1'

I've also tried to just call the script component directly from the Guiscript using this code:

 gameObject.Find("GameController").GetComponent(Gamecontroller);

I'm able to find the script component, but I'm unsure what to do with it. I tried to do this to attach the variable to my texture, but got an error:

 GUI.DrawTexture(Rect(600,410,100,100), PowerupTeddy, ScaleMode.ScaleToFit, true, 10.0f.GameController.PowerUpTeddy); //I guess you can't call the variable using this method:

So my long winded question: What is the best way to display GUI elements that rely on variables to display? IE health, current weapon, etc. Thanks in advance for any help.

Side note: I've also t

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 fafase · May 17, 2012 at 01:19 PM

guiTexture.texture = TeddyTexturGamecontroller.PowerUpTeddy];

] at the end, remove it.

Also, you declare static var PowerUpTeddy

but use var PowerUpTeddy = 1;

You actually declare a new variable in the Awake()

And make sure you spell the variables right you wrote PowerupTeddy in the last example.

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 Marvin Hawkins · May 18, 2012 at 11:17 AM 0
Share

Thanks, I did that, but that only resulted in an error: $$anonymous$$ identfier referencing the 'game controller'

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to display health on screen as text? 1 Answer

How to group variables in the Inspector? 5 Answers

How to prevent guitexture from vertically shrinking? 0 Answers

changing a variable with a gui button 1 Answer

GUI SCREW UPS! 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