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 dave_nguyen · Jul 04, 2013 at 09:25 AM · dooropenbatterycharge

How to pick up battery to open door?

Hi guys, my game is about a maze that is character have to collect enough battery to open the door, here is my script about the open door, can someone help me scripts for battery? Another thing is how we put a battery charge bar on the screen so player will know he has enough 4 batteries to open the door? Please help me, thank guys.

 var door: Transform;
 
 var angleOpen: int;
 var angleClose: int;
 var speedOpen: int = 1000;
 
 function OnTriggerStay(other:Collider){
     if (door.transform.localEulerAngles.y < angleOpen){
         door.transform.Rotate(Vector3.up*Time.deltaTime*speedOpen);
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Oribow · Jul 04, 2013 at 10:37 AM

Make the battery collider be a trigger. The Colliders of the Playermodel must have the Tag Player. Attached this as a Script on it:

 function OnTriggerEnter(var col : Collider)
     {
     if(col.tag == "Player")
     {
     col.GetComponent(PlayerScript).Battery++;
     Destroy(col.gameObject);
     }
     }

Attached the Variable Battery as public to the PlayerScript(if you havent a PlayerScript make ones in js). Then write in your Doorscript this:

 //this Variable outside the function
 public var pl: PlayerScript;
 
 if(door.localEulerAngels.y<angelOpen&& pl.Battery>=4)

to show it on the Screen write in your PlayerScript:

 function OnGUi()
 {
 GUI.label(Battery.ToString(),Rect(your Position));
 }



To have a Bar write instant of the Gui label this:

 GUI.texture(theBarTexture,Rect(posx,posy,widht*Battery,height));

This is much esay because you mustn have a texture for every Value.

If Batterys equal zero the bar widht*zero is zero

If Batterys equal one the bar widht* one is your size multiplicatet with one

.....

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
avatar image
0

Answer by senrohit · Jul 04, 2013 at 10:11 AM

Step 1. make a GUI Texture like your battery for four different levels. eg.: for 20 percnt, 40 percent, 60 percent and so on.

Step 2. Write this piece of pseudecode var h00: Texture2D; var h10: Texture2D; var h20: Texture2D; var h30: Texture2D; var h40: Texture2D; var h60: Texture2D; var h80: Texture2D; var h100: Texture2D;

var Bhealth=100;

function Update(){

var g_health= gameObject.Find("GUI_Health"); if(Bhealth>80) { g_health.guiTexture.texture= h100; return; } if(Bhealth>70) {

 g_health.guiTexture.texture= h80;
  }
  
  else if(Bhealth>50)
  {
  g_health.guiTexture.texture= h60;
  return;
  }
  else if(Bhealth>30) 
  {
  g_health.guiTexture.texture= h40;
  return;
  }
 else if(Bhealth>20)
  {
  g_health.guiTexture.texture= h30;
  return;
  }
  else if(Bhealth>10)
  {
  g_health.guiTexture.texture= h20;
  return;
  }
 else if(Bhealth>5)
  {
  g_health.guiTexture.texture= h10;
  return;
  }
  else if(Bhealth<=0)
  {
  g_health.guiTexture.texture= h00;
  
  return;
  }
  

}

something like this...

try mate.

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

17 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

Related Questions

Shooting target to trigger a door to open 1 Answer

Open door with key 1 Answer

Rotate the door according to mouse movement 1 Answer

Button at one end of the room opens door on other 0 Answers

Help with door animation 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