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 bpears · Jan 21, 2013 at 01:44 AM · javascriptgui

MissingFieldException UnityEngine.GUITexture.width not found?

Not sure why I am getting this error... Am I using .width wrong? Should I be using pixelinset? sorry, still learning.

 @script ExecuteInEditMode()
 
 var hitPoints : int;
 var painSound : AudioClip;
 var die : AudioClip;
 var deadReplacement : Transform;
 var mySkin : GUISkin;
 var explShake : GameObject;
 private var radar : GameObject;
 private var maxHitPoints = 100;
 var healthBarOriginalWidth = 100;
 var healthBar : GUITexture;
 var damageTexture : Texture;
 private var time : float = 0.0;
 private var alpha : float;
 private var callFunction : boolean = false;
 
 function Start(){
     maxHitPoints = hitPoints;
     alpha = 0;
 }
 
 function Update(){
     if (time > 0){ 
         time -= Time.deltaTime;
     }
     alpha = time;
 }
 
 function PlayerDamage (damage : int) {
     if (hitPoints < 0.0)
         return;
 
         // Apply damage
         hitPoints -= damage;
         audio.PlayOneShot(painSound, 1.0 / audio.volume);
         time = 2.0;        
     
 
     // Are we dead?
     if (hitPoints <= 0.0)
         Die();
         
 healthBar.pixelInset.width = - healthBarOriginalWidth * (hitPoints/maxHitPoints);
 }
 
 //Picking up MedicKit
 function Medic (medic : int){
     
     hitPoints += medic;
     
     if(hitPoints > maxHitPoints)
     hitPoints = maxHitPoints;
 }
 
 function Die () {
     if(callFunction)
     return;
     callFunction = true;
     
     if (die && deadReplacement)
         AudioSource.PlayClipAtPoint(die, transform.position);
 
     // Disable all script behaviours (Essentially deactivating player control)
     var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
     for (var b in coms) {
         var p : MonoBehaviour = b as MonoBehaviour;
         if (p)
             p.enabled = false;
     }
     // Disable all renderers
     var gos = GetComponentsInChildren(Renderer);
     for( var go : Renderer in gos){
         go.enabled = false;
 
     }
     if(radar != null){
         radar = gameObject.FindWithTag("Radar");
         radar.gameObject.SetActiveRecursively(false);
     }
     Instantiate(deadReplacement, transform.position, transform.rotation);
     yield WaitForSeconds(4.5);
     LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.black, 2.0);
 }
 
 
 function OnGUI () {
     GUI.skin = mySkin;
     GUI.contentColor = Color.red;
     
     
     GUI.color = Color(1.0, 1.0, 1.0, alpha); //Color (r,g,b,a)
     GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), damageTexture);
 }
 
 function Exploasion(){
     explShake.animation.Play("exploasion");
 }
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

Answer by sparkzbarca · Jan 21, 2013 at 03:00 AM

Yea you cant use GUITexture.width because it doesn't exist.

GUITexture contains no function or member variable called width.

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 bpears · Jan 21, 2013 at 03:08 AM 0
Share

how do I go about manipulating the guitextures width? I edited to this, but still does not work?

healthBar.pixelInset.width = - healthBarOriginalWidth * (hitPoints/maxHitPoints);

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

11 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

Related Questions

Cropped Label Problem - Big Font - Unity3D 1 Answer

OnGUI and Event.current 2 Answers

How to draw texture in C# without using (new Rect) 1 Answer

GUI opacity. 1 Answer

Coordinates of GUITexture 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