Last active
December 19, 2020 17:16
-
-
Save tvl83/b30e07dea4ec858e3d8085de4590ad3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class loc : Monobehaviour | |
{ | |
/*sir this code is all about | |
when my character touches the touchingGameobject object | |
it will destroy player aftee 30s | |
*/ | |
public Transform touchingGameobject; | |
public Transform player; | |
public float speed; | |
public Transform camera; | |
public Transform fire; | |
public float healthis; | |
void start() | |
{ | |
// this code is a syntax error and does nothing so I am commenting it out | |
// healthis <= 0; | |
// healthis >= 1; | |
} | |
void update() | |
{ | |
if (touchingGameobject && healthis <= 0) | |
{ | |
//the player die when the player life is lesser than 1 which is equal to 0 | |
Destroy(player, 30); // The destroy takes 2 parameters, separated by a comma. the second number is how many seconds before it will be destroy. you dont use the * symbol to do this. You also don't put an s after the number. | |
// this code wont take health off little by little. it will wait 30 seconds and then destroy the object instantly. | |
Debug.Log("i am dieing little by little"); | |
Transform.LookAt(camera); | |
} | |
//This part make the player not to die, when the player health bar is created than 1 | |
else if (touchingGameobject && healthis >= 1) | |
{ | |
// fixed the destroy method | |
Destroy(fire, 2); | |
transform.position = Vector3.up * speed * Time.deltaTime; | |
Debug.Log("to powerful to kill player right now"); | |
} | |
if (healthis <= 0 && touchingGameobject) | |
{ | |
// fixed the destroy method | |
Destroy(player, 30); | |
Debug.Log("player says game over"); | |
} | |
else if (healthis >= 0 && touchingGameobject) | |
{ | |
// fixed the destroy method | |
Destroy(fire, 2); | |
Debug.Log("player says game just began"); | |
} | |
} | |
} |
but sir, how can i add an health bar to this code
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok sir........ now i understand.....