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 Davidflynn · Oct 12, 2011 at 09:23 PM · androidcollsion

Collison Kills

Im wanting to make it so that when my ball collides with an object it is killed and looses a life at three lifes gone it looses game i know how to run game over just having problems with the lifes. I was wondering if some one could give me a basic code to get stated with im a little new to trying to design for android devices.

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 aldonaletto · Oct 12, 2011 at 10:21 PM

You must create a control script - let's call it Control.js - to hold all important variables (like health, lives, points etc.) and attach it to an empty object (or any object that's not destroyed during the level) - this could be the Control script:

static var lives = 3; // control the player lives

function Update(){ if (lives

function OnDestroy(){
    Control.lives -= 1; // decrement one life when the ball is destroyed
}
Comment
Add comment · Show 2 · 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 Davidflynn · Oct 13, 2011 at 01:26 AM 0
Share

Ok what I have is a blackHole like item that is using the fallowing code>

var spawnPoint : Transform; var theShadow : GameObject;

function OnTriggerEnter (other : Collider) { other.gameObject.active = false; theShadow.active = false;

   yield new WaitForSeconds (0.5);
 
   other.transform.position = spawnPoint.position;
 
   other.gameObject.active = true;
   theShadow.active = true;

}

i not quite shure how i can add what u showed to this the code above is on my black hole witch causes to respawn i want it to also remove a life. The code for the lives i want on the ball so that it dies im make a ball maze game.

avatar image aldonaletto · Oct 13, 2011 at 06:18 AM 0
Share

Ok, you're not destroying the ball, just moving it back to the spawn point. In this case, you can decrement the lives in your trigger event:

function OnTriggerEnter(other: Collider){
  Control.lives -= 1; // decrement life count
  other.gameObject.active = false;
  ...
You can also attach the Control script to the ball, since it's not being destroyed.

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

How to move 2D textures? 0 Answers

AssetBundle Android 1 Answer

How Cast a ray between two points and return all points intercepted? 0 Answers

Changing material with C# lags on Windows phone but not android 1 Answer

What program code do you prefer learning when creating an android game and have in mind to convert it to iOS later? 3 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