I am new to Unity and C#.
I am trying to make a simple program which will execute in console it will tell the user to wait for a certain time after the user click SPACE the computer will say how much he waited.
SO it's a simple code.
For doing this I have to generate a random number and some keyboard input is required.
But when I enter spacebar nothing happens.
NO COMPILATION ERROR.
Random Number generates number 0 only.
CODE:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class droid : MonoBehaviour {
float startTime;
float playerTime;
float targetTime;
// Use this for initialization
void Start () {
target();
}
// Update is called once per frame
void Update () {
playerTime = Time.time - startTime;
if (Input.GetKeyDown(KeyCode.Space))
{
print("You took " + playerTime);
}
}
void target() {
print("Your Time " + targetTime);
targetTime = Random.Range(0, 10);
startTime = Time.time;
}
}