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 08, 2012 at 01:59 PM · triggerdeadlose

if others are dead, do this

Hi, again :) I'm trying make it so that when a character falls off the edge and collides with my fallour floor - He's classed as dead, and lets say in a four player game, when the 3 other opponents are dead, the 1 alive player (dead=false) wins.

What I'm asking for is there a way to check if 3 of my 4 charaters are dead, and if so, to open up a winscreen or gui depending on winner "Player 1 wins".

 private var dead = false;
 
 function OnTriggerEnter (other : Collider) 
 {  
         dead = true;       
 }

Thank you so, so much :)

Comment
Add comment · Show 1
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 sjefke31 · Mar 08, 2012 at 03:07 PM 0
Share

Using a for loop will do the trick in your case. $$anonymous$$ore information on for loops (as they can be really specific) can be found here: http://answers.unity3d.com/questions/11547/how-do-i-use-for-to-create-loops-in-my-script-and.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FishBone · Mar 08, 2012 at 03:06 PM

If you have a list of your players gameobjects somewhere, make the dead-variable public and loop through the players to check how many of them is dead.

 var deadPlayers : int = 0;
 for(int i=0; i<_players.Length; i++){
     if (_players[i].dead)
         deadPlayers++;
 }
 
 if (deadPlayers >= 3)
     ShowWinScreen();
Comment
Add comment · Show 5 · 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 SirGive · Mar 08, 2012 at 03:17 PM 0
Share

could always use a get and set property that increments each death and would check to see if it was greater than the number of players. Don't know the syntax for unityscript, but it seems like that would be an efficient way of doing so ins$$anonymous$$d of looping every frame.

avatar image LittleCat1 · Mar 08, 2012 at 03:28 PM 0
Share

Thanks :) Sorry, It's been a bit of a long day, and I'm a bit shattered. What do I actually need to do? Turn deadPlayers into a static var

avatar image LittleCat1 · Mar 08, 2012 at 03:34 PM 0
Share

static var deadPlayers = false;

function OnTriggerEnter (other : Collider) {
deadPlayers = true;
Debug.Log (other.gameObject.name);
}

&

static var deadPlayers : int = 0;

function Update (){

for(int i=0; i<_players.Length; i++){ if (_players[i].dead) deadPlayers++; } }

if (deadPlayers >= 1) ShowWinScreen();

nomatter what I do, I'm still getting errors as it's not reading it as a integer (ecpecting; found "i" - 3rd line, 7th char)

avatar image FishBone · Mar 08, 2012 at 03:48 PM 0
Share

sorry not used to java, it should be

for (var i:int = 0; i<_players.Length; i++) {

But what SirGave said is true, so you should maybe do it that way ins$$anonymous$$d.

avatar image LittleCat1 · Mar 08, 2012 at 04:01 PM 0
Share

Thanks :) Still getting errors, but I think I'll just have to fiddle more. How add my 'players' to the _Players identifier?

@Sir Give/Anyone - I have no idea how to impliment this, is there anychance you could write something up for me? I know it's a huge ask, but I'd be forever grateful :) It really doesn't matter if it's in C# as I've got a friend that'll 'translate' over to Java if needed.

Thanks for being awesome :)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't click gameobject when over another trigger? 1 Answer

flickering lights when player gets near 1 Answer

Projectile reflection 1 Answer

Putting an object somewhere to destroy something else 1 Answer

Bullet triggers wrong collider 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