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 jacques 1 · Apr 04, 2011 at 11:45 PM · killhealth

strange things in my script

so im watching atutorial (tornadotwins) and im trying to die but i useally dont what happens is when i get hit once most of the time it counts as 2 and when i am 1 away from dieing i just dont, i die when falling out of bouds but not from the fire balls i want to be hit by here is the health script any ideas?:

var health1 : Texture2D; //one live left var health2 : Texture2D; //two lives left var health3 : Texture2D; //full health var bodypart1 : Transform; var bodypart2 : Transform;

static var LIVES = 3; static var HITS = 0;

function Update () { print("Lives: "+LIVES+" Hits: "+HITS); //lives: 3 Hits: 0

 switch(LIVES)
 {
   case 3:
     guiTexture.texture = health3;
     break;

   case 2:
     guiTexture.texture = health2;
     break;

   case 1:
     guiTexture.texture = health1;
     break;

   case 0:
     //gameover script here
     break;
 }

 switch(HITS)
 {
   case 1:
     //disable bodypart 1
     bodypart2.renderer.enabled=false;
     break;

   case 2:
     bodypart1.renderer.enabled = false;
     bodypart2.renderer.enabled=false;
     break;

   case 3:
     LIVES -= 1;
     HITS = 0;
     MoveAround.dead = true;
     bodypart1.renderer.enabled = true;
     bodypart2.renderer.enabled = true;
     break;

 }

}

heres my controler 4 my character

//Moving around var speed = 3.0; var rotateSpeed = 3.0; //Shooting var bullitPrefab:Transform; //Dying static var dead = false;

//Geting hit var tumbleSpeed = 800; var decreaseTime = 0.01; var decayTime = 0.01; static var gotHit = false; private var backup = [tumbleSpeed, decreaseTime, decayTime];

function LateUpdate() { if(dead) { transform.position = Vector3(0,9,0);

   dead = false;
 }
 if(gotHit)
 {
   if(tumbleSpeed < 1)
   {
     //we're not hit anymore... reset & get back in the game!
     tumbleSpeed = backup[0];
     decreaseTime = backup[1];
     decayTime = backup[2];
     gotHit = false; 
   }
   else
   {
     //we're hit! Spin our character around  
     transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
     tumbleSpeed = tumbleSpeed-decreaseTime;
     decreaseTime += decayTime;
   }
 }

}

//function OnControllerColliderHit(hit : ControllerColliderHit) 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); } }

function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);

 //shooting!
 if(Input.GetButtonDown("Jump"))
 {
   var bullit = Instantiate( bullitPrefab, 
                            transform.Find("spawnPoint").transform.position,
                            Quaternion.identity);
   bullit.tag = "wormProjectile";
   bullit.rigidbody.AddForce(transform.forward * 2000);        
 }

}

@script RequireComponent(CharacterController)

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 Henri 1 · Apr 05, 2011 at 08:02 AM

Check out the Lerpz tutorial, they handle health and death in the scripts, to get an idea.

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

How to Make a "Kill Platform"? 1 Answer

PlayerHealth drops fast and wont reset 1 Answer

Lower Object Health If Collides With "Player" Tag,Lower Object Health If Collides With Player Tag 1 Answer

loss of life help 1 Answer

Death on Lava collision 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