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
1
Question by zmar0519 · Dec 24, 2010 at 07:49 PM · lifehealth

What am I doing wrong with my life script?

Hi. I am making a first person shooter and want to be able to make the player have life. The script should work, but it doesn't. I can't figure out what I am doing wrong.

var Life : int = 0; var GameOverLevel : String; var Damage = 5; var EnemyProjectile : Transform;

function OnCollisionEnter(myCollider : Collider) { if(myCollider.gameObject.name == (EnemyProjectile)) { Life -= Damage; } } function OnGUI() { GUI.Label (Rect (25, 25, 100, 30), "Life: "+Life); }

function update() {
if (Life == 0) { Application.LoadLevel (GameOverLevel); } }

Comment
Add comment · Show 2
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 Jesus_Freak · Dec 24, 2010 at 07:58 PM 0
Share

also, if that's not the case, how is your script not working?

avatar image Jesus_Freak · Dec 24, 2010 at 08:07 PM 0
Share

You also didn't comPlete your updat function just put two brackets at the end of the script. }}

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jesus_Freak · Dec 24, 2010 at 07:57 PM

you're saying to automatically game-over since you're lives are zero already. just make your lives 10 or something.

Edit: in the oncollisionenter function you need to make the parameter. :Collision, not :Collider for it to work. Make sure an object is a rigidbody for that function to even work!

also, if the problem is that the level isn't loading, you didn't add it to the build settings menu. file > build settings, just drag your scene file to the build settings, and to open it from the game,

Application.LoadLevel("GameOverLevel"); //just make sure the name of your level is the same as you wrote it in the LoadLevel script.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

insert semicolon 2 Answers

How to deplete health every second 2 Answers

Destroy 1 prefab object and changing the color/image 1 Answer

health regeneration after death 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