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 m-y · Jun 14, 2014 at 07:40 PM · c#android

How To Call Health Script From Another Script ?

hello i have An Empty gameobject i added health bar script to it as u can see in the picture it is called ( HealthBar )

 #pragma strict
 public var health : float; // var helath
 var texture1: Texture2D; // texture 2d
 var mat : Material; // material
 var x : float = 0;
 var y : float = 0;
 var w : float;
 var h : float;
 function Start () {
 health = 1000; // begining health is 100
 }
 function OnGUI(){
 if(Event.current.type.Equals(EventType.Repaint)){ //Is the game being drawn?
 var box : Rect = new Rect(x, y, w, h); // the postion of the drawn on screen
 Graphics.DrawTexture(box, texture1, mat);  // you draw the bo and texture2d and material
 }
 }
 function Update () {
 var healthy : float = 1-(health/100);
 if(healthy == 0){
  
  
  
 healthy =.1;
 }
 mat.SetFloat("_Cutoff", healthy);
  
 if ( health <= 0 )
 {
  
 GameOver() ;
 }
  
  
 }
  
  
  
 function GameOver ()
 {
  
  
 Application.LoadLevel("GameOver") ;
 }
 function AddHealth ()
 {
 health +=30 ;
 }

and that is the code of HealthBar Script this Script Called ( HelathBar1) what i want is to make the health Float Increase By ( 30) if a cube hit a bullet

the problem that when the bullet hit the cube nothing happen first i want to ask ? where should be the script who call the health bar script on ? on bullet or on the cube ? secound how to call the health bar and increase the health of it by ( 30 ) and that is my trying but it is not working

 #pragma strict
 private var player : GameObject  ;
  
 private var   HealthScript  :  HealthBar1 ;
  
  
 function Start () {
 //var  HealthScObject = GameObject.FindGameObjectWithTag ("Player");
 //if (HealthScObject != null)
 //        {
 //            HealthScript  =  HealthScObject.GetComponent ("HelthBar1");
 //        }
 //        if (HealthScript == null)
 //        {
 //            Debug.Log ("Cannot find 'GameController' script");
 //        }
  
  
 }
  
  
 function OnTriggerEnter (other : Collider)
 {
 if ( other.gameObject.tag == "Player")
 {
  
 other.GetComponent(HealthBar1).health += 30 ;
  
  
  
 }
  
  
 }
  

it is increase the health by ( 30 ) when it is Hit the HealthBar Empty Object who have the script (HealthBar1 )

if added Health bar script to the bullet it is working also so what should i do to call it with out added it to the bullet hope you help me

alt text

pro1.png (44.4 kB)
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 Wisteso · Jun 14, 2014 at 09:01 PM

Generally speaking the code needs to do something like this... (C# version)

 SomeClass sc = GameObject.Find("ObjectWithSomeClass").GetComponent<SomeClass>();
 
 sc.SomeMethod();
 
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

screenshot 0 Answers

Android Development; How to use SDK manager! 1 Answer

Distribute terrain in zones 3 Answers

Calling an android method from Unity3D with a JAR plugin 0 Answers

Procedural Spawning Theorems 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