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 Paige · Apr 07, 2011 at 06:54 PM · switchrespawnstatementtiming-issue

Issue with switch statement

Hey guys, I seem to be having some trouble with a switch statement I have in javascript. What is supposed to happen is the character gets hit 6 times, and on the 6th time he dies, respawns if there are any lives left.

Now, the problem I am having is on the 6th hit, the life is taken away, the body parts that are supposed to be rendered are rendered, but i am in the same spot, until the character gets hit again. The 7th hit is when the character goes to the respawn point, with a hit on him. I'll post a small portion of the code, but if more is needed, just ask.

Any help would be grateful, thanks guys.

switch(HITS) { case 1: //disable bodypart2 //bodyPart5.renderer.enabled = false; Sphere08.renderer.enabled = false; Sphere14.renderer.enabled = false;

 break;

 case 2:
     //disable bodypart2
     Sphere07.renderer.enabled = false;
     Sphere13.renderer.enabled = false;


 break;

 case 3:
     //disable bodypart3
     Sphere06.renderer.enabled = false;
     Sphere12.renderer.enabled = false;

 break;

 case 4:         
     //disable bodypart4
     Sphere05.renderer.enabled = false;
     Sphere11.renderer.enabled = false;

 break;

 case 5:
     //disable bodypart5
     Sphere04.renderer.enabled = false;
     Sphere10.renderer.enabled = false;

 break;


 case 6: 
     //Character is dead, respawn, lose a life, reset body parts
     CharacterMove.dead = true;
     LIVES -= 1;
     HITS = 0;

     Sphere08.renderer.enabled = true;
     Sphere14.renderer.enabled = true;

     Sphere07.renderer.enabled = true;
     Sphere13.renderer.enabled = true;   

     Sphere06.renderer.enabled = true;
     Sphere12.renderer.enabled = true;

     Sphere05.renderer.enabled = true;
     Sphere11.renderer.enabled = true;

     Sphere04.renderer.enabled = true;
     Sphere10.renderer.enabled = true;
 break;  

}

.

function LateUpdate() { if (checkPoint.originalSpawn == true) { if(dead) { transform.position = Vector3(40, 1, 17); transform.eulerAngles = Vector3(rotation.x, CharacterMove.rotationy, rotation.z); // rotation dead = false; } }

}

.

function OnTriggerEnter( hit : Collider) { if(hit.gameObject.tag == "fallout") { dead = true; //substract life here HealthControl.LIVES -= 1; }

 if(hit.gameObject.tag == "enemyProjectile")
 {
     //gotHit = true;
     HealthControl.HITS += 1;
     Destroy(hit.gameObject);
 }

}

Comment
Add comment · Show 10
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 Marnix · Apr 07, 2011 at 07:37 PM 0
Share

@Paige: Yes I need more. Where do you call Respawn?

avatar image Wibbs 1 · Apr 07, 2011 at 10:45 PM 0
Share

Definately need more code please - don't be afraid of posting the whole switch statement :)

avatar image Paige · Apr 08, 2011 at 01:17 AM 0
Share

added the full switch statement for you wibbs, as well as where the character respawn code is located. the checkPoint.originalSpawn code is for check points that are throughout the level and i have tested that code, and it works fine for collisions and all that $$anonymous$$arnix.

avatar image Paige · Apr 08, 2011 at 01:18 AM 0
Share

also, sorry about the code break for the second line of code which is in a different js script. im still trying to figure these forums out

avatar image Owen-Reynolds · Apr 08, 2011 at 11:55 PM 1
Share

So, HITS goes up on a bullet, but when does it run that big switch that uses HITS? If it isn't right after adding, there's your problem. A trick is to "play computer" and trace through everything a collision eventually does.

Show more comments

1 Reply

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

Answer by Paige · Apr 17, 2011 at 04:56 AM

Well, I found the problem. For not very good reasons at all, I chose to make a separate script for handling the player running into checkpoints, and as I was transferring over all the code of that to the main character script, I saw that the respawn scripts were in the OnTriggerEnter function. so, after adding the respawn code to the Update function, all is well. I had a feeling after Owen Reynolds mentioned tracing everything the collision eventually did. Finally I can move on, heh.

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

Anyone help with my switch statement? 0 Answers

problem with child arrangement script 0 Answers

Using the StartsWith function in a Switch Case Statement 1 Answer

What is wrong with my c# switch statement? 1 Answer

FPS Game - I am making an Aim System and need help (Calling all game scripters) 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