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 Ryzokuken · Jul 31, 2014 at 09:34 AM · c#guiongui

why is my GUI script bugging other GUI scripts?

so, i have many different GUI scripts attatched to my player object, one of which makes the player shoot enemies. So, i kinda figured out a way to identify the enemy being shot and display the health bar of THAT particular gameObject, but this particularly bugs my other GUI (crosshair, own hp bar etc.) in the initial phase, after which things get normal.

heres the script, please help::

 using UnityEngine;
 using System.Collections;
 
 public class hit : MonoBehaviour {
     private RaycastHit shot = new RaycastHit();
 
     public GameObject enemy;
     public enemyHp enemyhp;
 
     void OnGUI () 
     {
 GUI.Box (new Rect(420,10, enemyhp.curHealth/enemyhp.maxHealth*300, 20),"Enemy Health");
     }
 
     void Start () 
     {
     
     }
     
     void Update () 
     {
         Vector3 dir = transform.TransformDirection(Vector3.forward);
         Vector3 pos1 = gameObject.transform.position;
         if (Input.GetButtonUp ("Fire1")) 
         {
             if (Physics.Raycast(pos1, dir, out shot, 20f)) 
             {    
                 enemyhp = shot.collider.gameObject.GetComponent<enemyHp> ();
                 enemyhp.curHealth = enemyhp.curHealth - 10;    
 
             }
         }
     }
 }
 









thanks all in advance :3

Comment
Add comment · Show 5
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 Klarax · Jul 31, 2014 at 09:39 AM 0
Share

I had a health bar, and then above it ammo amount. Looked ok in editor, building made the ammo gui disappear,

i found that putting calls to gui in several scripts attached to the same object causes major issues. i would try and put all gui in one place on a given object. Prolly work then.

You can however, have gui calls on different objects and no problems occur.

avatar image Arcadewiz · Jul 31, 2014 at 09:45 AM 0
Share

I don't understand your meaning by "bugs my other GUI". How exactly does it bug your GUIs.

avatar image Ryzokuken · Jul 31, 2014 at 10:38 AM 0
Share

the other boxes and buttons start blinking randomly and change positions this problem fixed after a few seconds

avatar image T27M · Jul 31, 2014 at 10:48 AM 0
Share

Does it happen every time? If you disable this script does the issue go away?

Can this ever return negative?

 enemyhp.curHealth/enemyhp.maxHealth*300


avatar image Arcadewiz · Jul 31, 2014 at 10:55 AM 0
Share

Just out of curiosity try in line 24

if (Input.GetButton ("Fire1"))

ins$$anonymous$$d of

if (Input.GetButtonUp ("Fire1"))

0 Replies

· Add your reply
  • Sort: 

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

25 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

Related Questions

C# Applying Transparency to a Single GUI.Button 1 Answer

C# Boolean Doesn't Change Value 1 Answer

Not working gui buttons 1 Answer

What is frame, How OnGuI is called every frame? 2 Answers

How do i change the GUI.Box font size and box size ? 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