how to write unit test cases in jasmine for this code? - karma-jasmine

private getTotalMinutesBetweenStartAndEnd(startTime: string, endTime: string): number {
// get each time's hour and min values
let [startHrs, startMins] = this.getHoursAndMinsFromTime(startTime);
let [endHrs, endMins] = this.getHoursAndMinsFromTime(endTime);
// time arithmetic (subtraction)
if (endMins < startMins) {
endHrs -= 1;
endMins += 60;
}
let mins = endMins - startMins;
let hrs = endHrs - startHrs;
// this handles scenarios where the startTime > endTime
if (hrs < 0) {
hrs += 24;
}
return hrs * 60 + mins;
}

Related

Age Calculator Difference in Kotlin [duplicate]

This question already has answers here:
How to create method for age calculation method in android
(7 answers)
Closed 4 months ago.
I have DatePicker Dialog, When I select date at that time I want to calculate age it's working but when I select date of current year at that time it showing the -1 age instead of 0 then how can solve this? Please help me to solve it.
My code is below:
public int getAge(int year, int month, int day) {
GregorianCalendar cal = new GregorianCalendar();
int y, m, d, noofyears;
y = cal.get(Calendar.YEAR);// current year ,
m = cal.get(Calendar.MONTH);// current month
d = cal.get(Calendar.DAY_OF_MONTH);// current day
cal.set(year, month, day);// here ur date
noofyears = (int) (y - cal.get(Calendar.YEAR));
LOGD("Age......", String.valueOf(noofyears));
if ((m < cal.get(Calendar.MONTH)) || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) {
--noofyears;
}
LOGD("Age......", String.valueOf(noofyears));
if (noofyears != 0) {
ageCount = noofyears;
} else {
ageCount = 0;
}
if (noofyears < 0)
throw new IllegalArgumentException("age < 0");
return noofyears;
}
java.time
For the sake of completeness and being up-to-date concerning packages, here is the way using java.time (Java 8+).
Java
public int getAge(int year, int month, int dayOfMonth) {
return Period.between(
LocalDate.of(year, month, dayOfMonth),
LocalDate.now()
).getYears();
}
Kotlin
fun getAge(year: Int, month: Int, dayOfMonth: Int): Int {
return Period.between(
LocalDate.of(year, month, dayOfMonth),
LocalDate.now()
).years
}
Both snippets need the following imports from java.time:
import java.time.LocalDate;
import java.time.Period
It's not recommended to use java.util.Date and java.util.Calendar anymore except from situations where you have to involve considerably large amounts of legacy code.
See also Oracle Tutorial.
For projects supporting Java 6 or 7, this functionality is available via the ThreeTenBP,
while there is special version, the ThreeTenABP for API levels below 26 in Android.
UPDATE
There's API Desugaring now in Android, which makes (a subset of) java.time directly available (no backport library needed anymore) to API levels below 26 (not really down to version 1, but will do for most of the API levels that should be supported nowadays).
private int getAge(String dobString){
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try {
date = sdf.parse(dobString);
} catch (ParseException e) {
e.printStackTrace();
}
if(date == null) return 0;
Calendar dob = Calendar.getInstance();
Calendar today = Calendar.getInstance();
dob.setTime(date);
int year = dob.get(Calendar.YEAR);
int month = dob.get(Calendar.MONTH);
int day = dob.get(Calendar.DAY_OF_MONTH);
dob.set(year, month+1, day);
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)){
age--;
}
return age;
}
Here is a Kotlin extension of the Date class returning the age corresponding to a Date object
val Date.age: Int
get() {
val calendar = Calendar.getInstance()
calendar.time = Date(time - Date().time)
return 1970 - (calendar.get(Calendar.YEAR) + 1)
}
It is compatible for all Android versions. If you wonder what '1970' is, that's the Unix Epoch. The timestamp is 0 on January 1, 1970.
private boolean getAge(int year, int month, int day) {
try {
Calendar dob = Calendar.getInstance();
Calendar today = Calendar.getInstance();
dob.set(year, month, day);
int monthToday = today.get(Calendar.MONTH) + 1;
int monthDOB = dob.get(Calendar.MONTH)+1;
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (age > 18) {
return true;
} else if (age == 18) {
if (monthDOB > monthToday) {
return true;
} else if (monthDOB == monthToday) {
int todayDate = today.get(Calendar.DAY_OF_MONTH);
int dobDate = dob.get(Calendar.DAY_OF_MONTH);
if (dobDate <= todayDate) { // should be less then
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static int getPerfectAgeInYears(int year, int month, int date) {
Calendar dobCalendar = Calendar.getInstance();
dobCalendar.set(Calendar.YEAR, year);
dobCalendar.set(Calendar.MONTH, month);
dobCalendar.set(Calendar.DATE, date);
int ageInteger = 0;
Calendar today = Calendar.getInstance();
ageInteger = today.get(Calendar.YEAR) - dobCalendar.get(Calendar.YEAR);
if (today.get(Calendar.MONTH) == dobCalendar.get(Calendar.MONTH)) {
if (today.get(Calendar.DAY_OF_MONTH) < dobCalendar.get(Calendar.DAY_OF_MONTH)) {
ageInteger = ageInteger - 1;
}
} else if (today.get(Calendar.MONTH) < dobCalendar.get(Calendar.MONTH)) {
ageInteger = ageInteger - 1;
}
return ageInteger;
}
Consider Today's Date - 30th August 2020
If Birthdate - 29th July 1993, the output - 27
If Birthdate - 29th August 1993, the output - 27
If Birthdate - 30th August 1993, the output - 27
If Birthdate - 31st August 1993, the output - 26
If Birthdate - 31st September 1993, the output - 26
Now for kotlin Language:
import java.util.Calendar
fun main(args: Array<String>) {
print(getAge(yyyy,mm,dd))
}
fun getAge(year: Int, month: Int, day: Int): String {
val dob = Calendar.getInstance()
val today = Calendar.getInstance()
dob.set(year, month, day)
var age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR)
if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) {
age--
}
val ageInt = age + 1
return ageInt.toString()
}
private void calculateAge() {
age.calcualteYear();
age.calcualteMonth();
age.calcualteDay();
age.calculateMonths();
age.calTotalWeeks();
age.calTotalHours();
age.calTotalMins();
age.calTotalSecs();
age.calTotalMilsecs();
// Toast.makeText(getContext(), "click the resulted button"+age.getResult() , Toast.LENGTH_SHORT).show();
result.setText("AGE (DD/MM/YY) :" + age.getResult());
}
after that create one class
public class AgeCalculation {
private int startYear;
private int startMonth;
private int startDay;
private int endYear;
private int endMonth;
private int endDay;
private int resYear;
private int resMonth;
private int resDay;
private Calendar start;
private Calendar end;
public String getCurrentDate()
{
end=Calendar.getInstance();
endYear=end.get(Calendar.YEAR);
endMonth=end.get(Calendar.MONTH);
endMonth++;
endDay=end.get(Calendar.DAY_OF_MONTH);
return endDay+":"+endMonth+":"+endYear;
}
public void setDateOfBirth(int sYear, int sMonth, int sDay)
{
startYear=sYear;
startMonth=sMonth;
startDay=sDay;
}
public void calcualteYear()
{
resYear=endYear-startYear/(365);
}
public void calcualteMonth()
{
if(endMonth>=startMonth)
{
resMonth= endMonth-startMonth;
}
else
{
resMonth=endMonth-startMonth;
resMonth=12+resMonth;
resYear--;
}
}
public void calcualteDay()
{
if(endDay>=startDay)
{
resDay= endDay-startDay;
}
else
{
resDay=endDay-startDay;
resDay=30+resDay;
if(resMonth==0)
{
resMonth=11;
resYear--;
}
else
{
resMonth--;
}
}
}
public String getResult()
{
return resDay+":"+resMonth+":"+resYear;
}
public String getAge(int year, int month, int day) {
Calendar dob = Calendar.getInstance();
Calendar today = Calendar.getInstance();
dob.set(year, month-1, day);
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) {
age--;
}
Integer ageInt = new Integer(age);
String ageS = ageInt.toString();
return ageS;
}
static int calculateAge(int birthdayDay, int birthdayMonth, int birthdayYear)
{
DateTime date = DateTime(birthdayYear, birthdayMonth, birthdayDay).toLocal();
DateTime now = DateTime.now().toLocal();
return now.difference(date).inDays ~/ 365.2425;
}
public int getAge(int year, int month, int day) {
final Calendar birthDay = Calendar.getInstance();
birthDay.set(year, month, day);
final Calendar current = Calendar.getInstance();
if (current.getTimeInMillis() < birthDay.getTimeInMillis())
throw new IllegalArgumentException("age < 0");
int age = current.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
if (birthDay.get(Calendar.MONTH) > current.get(Calendar.MONTH) ||
(birthDay.get(Calendar.MONTH) == current.get(Calendar.MONTH) &&
birthDay.get(Calendar.DATE) > current.get(Calendar.DATE)))
age--;
return age;
}
This is how I implement in my source code, I tested. Hope that it is useful :
public static int getAge(String dateTime, String currentFormat) {
SimpleDateFormat dateFormat = new SimpleDateFormat(currentFormat);
try {
Date date = dateFormat.parse(dateTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
Date currentDate = new Date();
Calendar currentCalendar = Calendar.getInstance();
currentCalendar.setTime(currentDate);
int currentYear = currentCalendar.get(Calendar.YEAR);
int currentMonth = currentCalendar.get(Calendar.MONTH);
int currentDay = currentCalendar.get(Calendar.DAY_OF_MONTH);
int deltaYear = currentYear - year;
int deltaMonth = currentMonth - month;
int deltaDay = currentDay - day;
if (deltaYear > 0) {
if (deltaMonth < 0) {
deltaYear --;
} else if (deltaDay < 0){
deltaYear --;
}
return deltaYear;
}
} catch (java.text.ParseException e) {
e.printStackTrace();
}
return 0;
}
String getAgeInOther(int year, int month, int day) {
Calendar today = Calendar.getInstance();
Calendar birth = Calendar.getInstance();
birth.set(year, month, day);
Calendar temp = Calendar.getInstance();
temp.set(year, month, day);
int totalDays = 0;
int intMonth=0,intDays=0;
for (int iYear = birth.get(Calendar.YEAR); iYear <= today.get(Calendar.YEAR); iYear++) {
if (iYear == today.get(Calendar.YEAR) && iYear == birth.get(Calendar.YEAR)) {
for (int iMonth = birth.get(Calendar.MONTH); iMonth <= today.get(Calendar.MONTH); iMonth++) {
temp.set(iYear, iMonth, 1);
if ((iMonth == today.get(Calendar.MONTH)) && (iMonth == birth.get(Calendar.MONTH))) {
totalDays += today.get(Calendar.DAY_OF_MONTH) - birth.get(Calendar.DAY_OF_MONTH);
} else if ((iMonth != today.get(Calendar.MONTH)) && (iMonth != birth.get(Calendar.MONTH))) {
totalDays += temp.getActualMaximum(Calendar.DAY_OF_MONTH);
intMonth++;
}else if ((iMonth == birth.get(Calendar.MONTH))) {
totalDays +=( birth.getActualMaximum(Calendar.DAY_OF_MONTH)- birth.get(Calendar.DAY_OF_MONTH));
} else if ((iMonth == today.get(Calendar.MONTH))){
totalDays += today.get(Calendar.DAY_OF_MONTH);
if (birth.get(Calendar.DAY_OF_MONTH)<today.get(Calendar.DAY_OF_MONTH))
{
intMonth++;
intDays=today.get(Calendar.DAY_OF_MONTH)-birth.get(Calendar.DAY_OF_MONTH);
}else {
temp.set(today.get(Calendar.YEAR),today.get(Calendar.MONTH)-1,1);
intDays=temp.getActualMaximum(Calendar.DAY_OF_MONTH)-birth.get(Calendar.DAY_OF_MONTH)+today.get(Calendar.DAY_OF_MONTH);
}
}
}
} else if ((iYear != today.get(Calendar.YEAR)) && (iYear != birth.get(Calendar.YEAR))) {
for (int iMonth = 0; iMonth < 12; iMonth++) {
temp.set(iYear, iMonth, 1);
totalDays += temp.getActualMaximum(Calendar.DAY_OF_MONTH);
intMonth++;
}
} else if (((iYear) == birth.get(Calendar.YEAR))) {
for (int iMonth = birth.get(Calendar.MONTH); iMonth < 12; iMonth++) {
temp.set(iYear, iMonth, 1);
if ((iMonth == birth.get(Calendar.MONTH))) {
totalDays += (birth.getActualMaximum(Calendar.DAY_OF_MONTH)-birth.get(Calendar.DAY_OF_MONTH));
} else {
intMonth++;
totalDays += temp.getActualMaximum(Calendar.DAY_OF_MONTH);
}
}
} else if (iYear == today.get(Calendar.YEAR)) {
for (int iMonth = 0; iMonth <= today.get(Calendar.MONTH); iMonth++) {
temp.set(iYear, iMonth, 1);
if ((iMonth == today.get(Calendar.MONTH))) {
totalDays += today.get(Calendar.DAY_OF_MONTH);
if (birth.get(Calendar.DAY_OF_MONTH)<today.get(Calendar.DAY_OF_MONTH))
{
intMonth++;
intDays=today.get(Calendar.DAY_OF_MONTH)-birth.get(Calendar.DAY_OF_MONTH);
}else {
temp.set(today.get(Calendar.YEAR),today.get(Calendar.MONTH)-1,1);
intDays=temp.getActualMaximum(Calendar.DAY_OF_MONTH)-birth.get(Calendar.DAY_OF_MONTH)+today.get(Calendar.DAY_OF_MONTH);
}
} else {
intMonth++;
totalDays += temp.getActualMaximum(Calendar.DAY_OF_MONTH);
}
}
}
}
int ageYear=intMonth/12;
int ageMonth=intMonth%12;
int ageDays=intDays;
//TODO if you want age in YEAR:MONTH:DAY REMOVE COMMENTS
//TODO return ageYear+":"+ageMonth+":"+ageDays;
return ""+totalDays;//todo TOTAL AGE IN DAYS
}
public static String calculateAge(String strDate) {
int years = 0;
int months = 0;
int days = 0;
try {
long timeInMillis = Long.parseLong(strDate);
Date birthDate = new Date(timeInMillis);
//create calendar object for birth day
Calendar birthDay = Calendar.getInstance();
birthDay.setTimeInMillis(birthDate.getTime());
//create calendar object for current day
long currentTime = System.currentTimeMillis();
Calendar now = Calendar.getInstance();
now.setTimeInMillis(currentTime);
//Get difference between years
years = now.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
int currMonth = now.get(Calendar.MONTH) + 1;
int birthMonth = birthDay.get(Calendar.MONTH) + 1;
//Get difference between months
months = currMonth - birthMonth;
//if month difference is in negative then reduce years by one and calculate the number of months.
if (months < 0) {
years--;
months = 12 - birthMonth + currMonth;
if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE))
months--;
} else if (months == 0 && now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) {
years--;
months = 11;
}
//Calculate the days
if (now.get(Calendar.DATE) > birthDay.get(Calendar.DATE))
days = now.get(Calendar.DATE) - birthDay.get(Calendar.DATE);
else if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) {
int today = now.get(Calendar.DAY_OF_MONTH);
now.add(Calendar.MONTH, -1);
days = now.getActualMaximum(Calendar.DAY_OF_MONTH) - birthDay.get(Calendar.DAY_OF_MONTH) + today;
} else {
days = 0;
if (months == 12) {
years++;
months = 0;
}
}
//adarsh
if (currMonth > birthMonth) {
if (birthDay.get(Calendar.DATE) > now.get(Calendar.DATE)) {
months = months - 1;
}
}//---------------------------------
} catch (Exception e) {
e.printStackTrace();
}
//Create new Age object
return years + " Y " + months + " M " + days + " days";
}
Here is my solution in Kotlin:
import java.time.LocalDateTime
fun getAge(birthYear: Int, birthMonth: Int, birthDay: Int): Int {
var age: Int = LocalDateTime.now().year - birthYear
if (birthMonth > LocalDateTime.now().monthValue || birthMonth == LocalDateTime.now().monthValue && birthDay > LocalDateTime.now().dayOfMonth) { age-- }
if (age < 0) { age = 0 }
return age
}
int age =0;
age = yearLatest - yearBirth;
if (monthAge > currentMonth) {
if (age != 0) {
age = age - 1;
}
} else if(monthAge == currentMonth){
if (dayAge > currentDay) {
if (age != 0) {
age = age - 1;
}
}
}
return age;
If we want to directly check if age is below or above X age then we can use LocalDate type, work for all the Android API levels.
LocalDate.now().minusYears(18).isBefore(value) //value is your localDate
This is the shortest I could get it to.
static int calculateAge(Calendar birthDay){
Calendar today = Calendar.getInstance();
int age = today.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
if (birthDay.get(Calendar.DAY_OF_YEAR) < today.get(Calendar.DAY_OF_YEAR)) {
age--;
}
return age;
}
New Language Dart using DateTime
static int getPerfectAgeInYears(DateTime dob,DateTime today) {
dob = DateTime(dob.year,dob.month,dob.day);
int ageInteger = 0;
today = DateTime(today.year,today.month,today.day);
ageInteger = today.year-dob.year;
if (today.month == dob.month) {
if (today.day < dob.day) {
ageInteger = ageInteger - 1;
}
} else if (today.month < dob.month) {
ageInteger = ageInteger - 1;
}
return ageInteger;}
Call as print(getPerfectAgeInYears(DateTime(2000,6,4),DateTime.now()));
Consider Today's Date - 30th August 2020
If Birthdate - 29th July 1993, the output - 27
If Birthdate - 29th August 1993, the output - 27
If Birthdate - 30th August 1993, the output - 27
If Birthdate - 31st August 1993, the output - 26
If Birthdate - 31st September 1993, the output - 26

How to script an Interval in Photoshop

I am trying to script something in Photoshop that has to run every X seconds. In JavaScript it would look like this:
function run() {
    alert('Ran!')
}
setInterval(run, 1000)
 
But in Photoshop's JavaScript, "setInterval is not a function". Any idea how else I would get any form of interval working?
This is by no means a good example, however, it stalls for a second. Those that don't know it there's no pause or sleep function in ECMA 3. I don't use a while loop as that's asking for trouble in Photoshop and may lock things up - which may lose your work.
sleepy(1000)
function sleepy(milliseconds)
{
// Start the fans please! I mean timer
var dStart = new Date().getTime();
var longtime = 10000000;
for(var i = 0 ; i < longtime; i++)
{
var now = new Date().getTime();
if (now > dStart + milliseconds)
{
// Stop the fans!
var dEnd = new Date().getTime();
var timeTaken = (dEnd - dStart)/1000;
var msgTime = (timeTaken + " seconds.");
alert(msgTime);
// alert("Ran");
return;
}
}
}
or if it's just a second, just calculate the Fibbonaci sequence to 28 spots. It's also machine dependant (and rather slower than expected in Photoshop)
function fibonacci(n)
{
if (n < 2)
return n
else
{
return fibonacci(n-1) + fibonacci(n-2);
}
}
var numOfNums = 28; // 0.91 seconds
// var numOfNums = 29; // 1.47 seconds
// var numOfNums = 30; // 2.39 seconds
// var numOfNums = 31; // 3.8 seconds
var dStart = new Date().getTime();
var msg = "";
for(var i = 0 ; i < numOfNums; i++)
{
msg += fibonacci(i) + ", ";
}
var dEnd = new Date().getTime();
var timeTaken = (dEnd - dStart)/1000;
// alert(msg);
alert(timeTaken);

Is there an issue with trying to pass a constant or variable to a rem() method in kotlin?

Is there an issue with trying to pass a constant or variable to a rem() method in kotlin?
object TimeCalc {
private const val SECONDS: Int = 1000
private const val MINUTES: Int = SECONDS * 60
private const val HOURS: Int = MINUTES * 60
private const val DAYS: Int = HOURS * 24
fun timeDiff(sTime: Long, eTime: Long){
Log.i("Test", "sec $SECONDS: min $MINUTES : hrs $HOURS : days $DAYS")
var startTime = sTime
var endTime = eTime
var mDiff: Int
var mHours: Int
var mMinutes: Int
var mSeconds:Int
var mMilliS: Int
Log.i("Test", "$startTime - $endTime")
mDiff = (endTime - startTime).toInt()
Log.i("Test", "Diff = $mDiff")
**mHours = mDiff.rem(DAYS)**
Log.i("Test", "Hours = $mHours")
Log.i("Test", "${mHours}")
}
}
Result
I/Test: sec 1000: min 60000 : hrs 3600000 : days 86400000
I/Test: 1545062123189 - 1545062217296
I/Test: Diff = 94107
I/Test: Hours = 94107
I/Test: 94107

How do I convert timespan to OAdate?

I am using Zedgraph and for x-axis, they require us to convert to OADate. I am plotting live stock chart and I want to show the last 60sec.
So I use zedGraphControl1.GraphPane.XAxis.Scale.Max and zedGraphControl1.GraphPane.XAxis.Scale.Min. For the Max value, I will set it to the latest time while for the Min value I plan to set to the latest time minus 60 secs (variable). I will store the 60sec in the type timespan. But the problem is that timespan does not have the function toOADate.
Implement your own method!
all you need to know is
1 day = 24 hours
1 hour = 60 minutes
1 minute = 60 seconds
1 second = 1000 milliseconds
Example: let's say i have time t= 456722622 msec
struct TimeDetailed
{
public int millisec;
public int seconds;
public int minutes;
public int hours;
public int days;
};
static TimeDetailed tConverted;
int t = 456722622;
public void function(int a)
{
int d,h,m,s;
d=h=m=s=0;
while(a >= 86400000) // milliseconds per day
{
a -= 86400000;
d++;
}
while(a >= 3600000) // milliseconds per hour
{
a -= 3600000;
h++;
}
while(a >= 60000) // milliseconds per minute
{
a -= 60000;
m++;
}
while(a >= 1000) // milliseconds per second
{
a -= 1000;
s++;
}
tConverted.days = d;
tConverted.hours = h;
tConverted.minutes = m;
tConverted.seconds = s;
tConverted.millisec = a;
}
function(t);
the output is:
tConverted.days = 5
tConverted.hours = 6
tConverted.minutes = 52
tConverted.seconds = 2
tConverted.millisec = 622
Though I didn't test this code but you can similarly make one

Player should win when all objects are collected

I have a simple game where the player needs to collect 4 game objects within 30 sec. Now I already created the timer, so I need to let the game know that if all game objects are collected under the time limit the player wins.
This is my code so far:
using UnityEngine;
using System.Collections;
public class GameState : MonoBehaviour
{
public static int count = 0;
public float seconds = 30;
public float minutes = 0;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (seconds <= 0)
{
seconds = 30;
if (minutes >= 1)
{
minutes -- ;
}
else
{
minutes = 0;
seconds = 0;
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":0" + seconds.ToString("f0");
}
}
else
{
seconds -= Time.deltaTime;
}
if (Mathf.Round(seconds) <=9)
{
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":0" + seconds.ToString("f0");
}
else
{
GameObject.Find("TimerText").guiText.text = minutes.ToString("f0") + ":" + seconds.ToString("f0");
}
if(count >= 1)
{
print("You Won!");
}
}
void OnTriggerEnter(Collider collide)
{
if (collide.transform.tag == "Cube")
{
count = count + 1;
Destroy (collide.gameObject);
}
}
}
Note: cube is one of the game object that needs to be picked up.
you could interrupt the game or show a victory menu or something when you have all the cubes collected
void Update ()
{
bool cubescollected = false;
if(cubescollected == 4)
{
ShowVictoryOrSomething();
cubescollected = true
}
if(cubescollected == true)
return;
... your timer code
}
good luck and happy coding