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 LittleCat1 · Mar 06, 2012 at 11:16 AM · colliderlivesdead

Lives/Death Script

Hi, I've got a game which is two balls on a platform, and they've got to push the other off, best of 3. But I'm struggling with the 'dead' script (when they fall off the side, collide with my floor and lose a life and restart).

The issue is - I'm not using a Character controller on either ball - so CharacterColliderHit doesn't work. How can I rectify that?

Script -

private var dead = false;

function OnControllerColliderHit(hit : ControllerColliderHit)

 {
     if(hit.GameObject.tag == "Death Zone")
     {
         //dead = true;
         Debug.Log ("Dead = True");        
         //Lives.AmountLives -= 1;
         
     }

}

I want it to find an object (rather than a tag), or make it work on just a general hit, not a controllercollider.

Thanks p.s. I'm really new at this, and I honestly have searched for an answer :(

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
Best Answer

Answer by fafase · Mar 06, 2012 at 11:33 AM

Use

private var dead = false;

 function OnCollisionEnter(hit : Collision)
 {
     if(hit.gameObject.tag == "Death Zone")
     {
        dead = true;      
        Lives.AmountLives -= 1;
     }
 }

and in update:

if(dead){
    transform.position = Vector3(x,y,z); //Location where you want the ball to respawn
    dead = false;
}
Comment
Add comment · Show 10 · 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 LittleCat1 · Mar 06, 2012 at 12:44 PM 0
Share

Now I'm just getting a "NullReferenceException" :( Thanks though. Just not sure what I'm doing wrong though.

avatar image fafase · Mar 06, 2012 at 12:48 PM 0
Share

You should get more info about this null reference, telling where will help you. Null reference means you are trying to instantiate an object but there is nothing refered to it. LIke you want to shoot a bullet but you have no prefab for the bullet so it is shooting empty.

avatar image LittleCat1 · Mar 06, 2012 at 12:56 PM 0
Share

"NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) Lives 2.OnCollisionEnter (UnityEngine.Collision hit) (at Assets/Scripts/Lives 2.js:5)"

Lives 2.js is the above code. This -> if(hit.GameObject.tag == "DeadArea")

I changed the tag of the object it references and the code, numerous times now, aswell to loads of different things. Still doesn't work. Thanks for the response :)

avatar image fafase · Mar 06, 2012 at 12:59 PM 0
Share

Did you tag or named your DeadArea object?

avatar image LittleCat1 · Mar 06, 2012 at 01:05 PM 0
Share

It's just called DeadArea, is that okay?

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Internal collisions 1 Answer

Find Game Objects With Tag 2 Answers

Yield Continuous Death 1 Answer

how to move the player away when it's hit 3 Answers

Not losing lives 2 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