c# - Unity2D: How to lock my game for a certain amount of time sort of like candy crush -
hi have 2d topdown rpg game, , wanted know if there way of locking game amount of time (countdown) when player loses of hearts (lives). , no matter user can not access game until countdown has complete. candy crush when lose of lives. far i've got panel slides down, saying gameover, when player dies (when of hearts gone). i'm not sure how put lock on game amount of time, want user sill go main menu if game still lock. said before want similar candy crush saga if player loses live have wait amount of time play game.
this script health script of player, can see game on panel linked ui manager:
public int curhealth; public int maxhealth = 3; vector3 startposition; public playerhealth playerhealthref; float counter; public animator anima; // drag panel in here again private ui_managerscripts uim; private playerscript ps; void start () { curhealth = maxhealth; startposition = transform.position; ps = gameobject.findgameobjectwithtag("playerscript").getcomponent <playerscript> (); } void update () { if (curhealth > maxhealth) { curhealth = maxhealth; } if (curhealth <= 0) { die (); } } void awake() { uim = gameobject.find ("uimanager").getcomponent<ui_managerscripts> (); } void die(){ if (playerprefs.haskey ("highscore")) { if (playerprefs.getint ("highscore") < ps.score) { playerprefs.setint ("highscore", ps.score); } } else { playerprefs.setint ("highscore", ps.score); } uim.enableboolanimator(anima); } public void damage(int dmg) { curhealth -= dmg; reset(); } void reset () { transform.position = startposition; gotomouse.target = startposition; } }
this uimanager script:
public audioclip swooshsound; public void disableboolanimator(animator anim) { anim.setbool ("isdisplayed", false); } public void enableboolanimator(animator anim) { anim.setbool ("isdisplayed", true); } public void navigateto(int scene) { application.loadlevel (scene); } public void exitgame() { application.quit (); } public void pausegame() { audiosource.playclipatpoint (swooshsound, transform.position); time.timescale = 0; } public void unpausegame() { time.timescale = 1; } }
thank :)
if want have player wait amount of time, should save datetime
file. then, when player tries play, have game check if date/time later date/time saved file. this:
//for saving file when player loses file.writealltext("path_to_file", datetime.now.addhours(1).tostring()); //for checking see if player can play if(convert.todatetime(file.readalltext("path_to_file")) < datetime.now) { //allow player play } else { //tell player can't play }
then change datetime.now.addhours(1)
many hours want player wait, or can change datetime.now.addminutes(1)
many minutes want player wait. hope helped :)
Comments
Post a Comment