Question by
KnightRiderGuy · Nov 29, 2015 at 02:11 AM ·
c#javascriptconvertconversionjava to c#
Convert Java to C#
Can someone convert this Java to C#?
#pragma strict
var Alarm : AudioClip ;
var timer: float = 3600;
var isFinishedTimer : boolean = true;
public var displayText : UnityEngine.UI.Text;
public var timeText : UnityEngine.UI.Text;
var minsDisplay : String;
var secsDisplay : String;
var mySeconds : int = 0;
private var oldTimer : float;
//Random Clips
var voices : AudioClip[];
/*//Begin New
function Awake ()
{
// Make LevelData a singleton, so we keep ourself alive and kill any clones
if ( FindObjectsOfType(CountdownTimerManager).Length != 1 ) // If one of me already exists I must be a clone, so destroy me (don't feel bad about it)
Destroy (gameObject);
else // I'm the original, so keep me around
DontDestroyOnLoad (gameObject);
}
//End New
/*function Awake () {
DontDestroyOnLoad (transform.gameObject);
}*/
function Start(){
oldTimer = timer;
}
function Update(){
if (!isFinishedTimer) {
timer -= Time.deltaTime;
}
CurrentTime();
}
function CurrentTime() {
var dt : System.DateTime = System.DateTime.Now;
var h : int = dt.Hour;
var m : int = dt.Minute;
var s : int = dt.Second;
timeText.text = h + ":" + m + ":" + s;
if(mySeconds != s)
{
mySeconds = s;
Timing();
}
}
function Timing()
{
if (timer > 0) {
//var minsDisplay : String = parseInt( timer / 60 ).ToString();
minsDisplay = parseInt( timer / 60 ).ToString();
//var secsDisplay : String = parseInt( timer ).ToString();
secsDisplay = parseInt( timer ).ToString();
if ( (timer - ( parseInt(minsDisplay) * 60)) > 10 ) {
secsDisplay = parseInt( timer - ( parseInt(minsDisplay) * 60) ).ToString();
}
else {
secsDisplay = "0" + parseInt( timer - ( parseInt(minsDisplay) * 60) ).ToString();
}
//displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Reaches End We Can Do Something Here
else {
timer += oldTimer;
GetComponent.<AudioSource>().PlayOneShot(Alarm);//Plays Alarm Sound
isFinishedTimer = true;//Sets Inspector Value to true or false based on what is set here
yield WaitForSeconds (5.8);//Wait Time Setting
//Do Something if Desired
//if (GetComponent.<AudioSource>().isPlaying) return; // don't play a new sound while the last hasn't finished
GetComponent.<AudioSource>().clip = voices[Random.Range(0,voices.length)];
GetComponent.<AudioSource>().Play();
Debug.Log ("Timer Ended");
}
displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Stop Button
public function GoTimerStop()
{
isFinishedTimer = true;
}
//Timer Start Button
public function GoTimerStart()
{
isFinishedTimer = false;
}
//Timer Settings
public function GoTimerSetting60Sec()
{
timer = 60;
}
public function GoTimerSetting5Min()
{
timer = 300;
}
public function GoTimerSetting10Min()
{
timer = 600;
}
public function GoTimerSetting20Min()
{
timer = 1200;
}
public function GoTimerSetting30Min()
{
timer = 1800;
}
public function GoTimerSetting40Min()
{
timer = 2400;
}
public function GoTimerSetting50Min()
{
timer = 3000;
}
public function GoTimerSetting1Hr()
{
timer = 3600;
}
public function GoTimerSetting1Point5Hr()
{
timer = 5400;
}
public function GoTimerSetting2Hr()
{
timer = 7200;
}
public function GoTimerSetting2Point5Hr()
{
timer = 9000;
}
public function GoTimerSetting3Hr()
{
timer = 10800;
}
Comment
Answer by Yulka · Nov 29, 2015 at 03:52 AM
Possibly so?
#pragma strict
AudioClip Alarm;
float timer = 3600;
bool isFinishedTimer = true;
public UnityEngine.UI.Text displayText;
public UnityEngine.UI.Text timeText;
string minsDisplay;
string secsDisplay;
int mySeconds = 0;
private float oldTimer;
//Random Clips
AudioClip[] voices;
/*//Begin New
function Awake ()
{
// Make LevelData a singleton, so we keep ourself alive and kill any clones
if ( FindObjectsOfType(CountdownTimerManager).Length != 1 ) // If one of me already exists I must be a clone, so destroy me (don't feel bad about it)
Destroy (gameObject);
else // I'm the original, so keep me around
DontDestroyOnLoad (gameObject);
}
//End New
/*function Awake () {
DontDestroyOnLoad (transform.gameObject);
}*/
void Start(){
oldTimer = timer;
}
void Update(){
if (!isFinishedTimer) {
timer -= Time.deltaTime;
}
CurrentTime();
}
void CurrentTime() {
System.DateTime dt = System.DateTime.Now;
int h = dt.Hour;
int m = dt.Minute;
int s = dt.Second;
timeText.text = h + ":" + m + ":" + s;
if(mySeconds != s)
{
mySeconds = s;
Timing();
}
}
IEnumerator Timing()
{
if (timer > 0) {
//var minsDisplay : String = parseInt( timer / 60 ).ToString();
minsDisplay = System.Convert.ToInt32( timer / 60 ).ToString();
//var secsDisplay : String = parseInt( timer ).ToString();
secsDisplay = System.Convert.ToInt32( timer ).ToString();
if ( (timer - ( System.Convert.ToInt32(minsDisplay) * 60)) > 10 ) {
secsDisplay = System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
}
else {
secsDisplay = "0" + System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
}
//displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Reaches End We Can Do Something Here
else {
timer += oldTimer;
GetComponent<AudioSource>().PlayOneShot(Alarm);//Plays Alarm Sound
isFinishedTimer = true;//Sets Inspector Value to true or false based on what is set here
yield return new WaitForSeconds(5.8f);//Wait Time Setting
//Do Something if Desired
//if (GetComponent.<AudioSource>().isPlaying) return; // don't play a new sound while the last hasn't finished
GetComponent<AudioSource>().clip = voices[Random.Range(0,voices.Length)];
GetComponent<AudioSource>().Play();
Debug.Log ("Timer Ended");
}
displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Stop Button
public void GoTimerStop()
{
isFinishedTimer = true;
}
//Timer Start Button
public void GoTimerStart()
{
isFinishedTimer = false;
}
//Timer Settings
public void GoTimerSetting60Sec()
{
timer = 60;
}
public void GoTimerSetting5Min()
{
timer = 300;
}
public void GoTimerSetting10Min()
{
timer = 600;
}
public void GoTimerSetting20Min()
{
timer = 1200;
}
public void GoTimerSetting30Min()
{
timer = 1800;
}
public void GoTimerSetting40Min()
{
timer = 2400;
}
public void GoTimerSetting50Min()
{
timer = 3000;
}
public void GoTimerSetting1Hr()
{
timer = 3600;
}
public void GoTimerSetting1Point5Hr()
{
timer = 5400;
}
public void GoTimerSetting2Hr()
{
timer = 7200;
}
public void GoTimerSetting2Point5Hr()
{
timer = 9000;
}
public void GoTimerSetting3Hr()
{
timer = 10800;
}
Answer by KnightRiderGuy · Nov 29, 2015 at 01:17 PM
Close @yulka but not working, I had to add in the top part of the Script and change the Audio clip array but it still does not work?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CountdownTimerManager : MonoBehaviour {
public AudioClip Alarm;
float timer = 3600;
bool isFinishedTimer = true;
public UnityEngine.UI.Text displayText;
public UnityEngine.UI.Text timeText;
string minsDisplay;
string secsDisplay;
int mySeconds = 0;
private float oldTimer;
//Random Clips
public AudioClip[] voices;
/*//Begin New
function Awake ()
{
// Make LevelData a singleton, so we keep ourself alive and kill any clones
if ( FindObjectsOfType(CountdownTimerManager).Length != 1 ) // If one of me already exists I must be a clone, so destroy me (don't feel bad about it)
Destroy (gameObject);
else // I'm the original, so keep me around
DontDestroyOnLoad (gameObject);
}
//End New
/*function Awake () {
DontDestroyOnLoad (transform.gameObject);
}*/
void Start(){
oldTimer = timer;
}
void Update(){
if (!isFinishedTimer) {
timer -= Time.deltaTime;
}
CurrentTime();
}
void CurrentTime() {
System.DateTime dt = System.DateTime.Now;
int h = dt.Hour;
int m = dt.Minute;
int s = dt.Second;
timeText.text = h + ":" + m + ":" + s;
if(mySeconds != s)
{
mySeconds = s;
Timing();
}
}
IEnumerator Timing()
{
if (timer > 0) {
//var minsDisplay : String = parseInt( timer / 60 ).ToString();
minsDisplay = System.Convert.ToInt32( timer / 60 ).ToString();
//var secsDisplay : String = parseInt( timer ).ToString();
secsDisplay = System.Convert.ToInt32( timer ).ToString();
if ( (timer - ( System.Convert.ToInt32(minsDisplay) * 60)) > 10 ) {
secsDisplay = System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
}
else {
secsDisplay = "0" + System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
}
//displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Reaches End We Can Do Something Here
else {
timer += oldTimer;
GetComponent<AudioSource>().PlayOneShot(Alarm);//Plays Alarm Sound
isFinishedTimer = true;//Sets Inspector Value to true or false based on what is set here
yield return new WaitForSeconds(5.8f);//Wait Time Setting
//Do Something if Desired
//if (GetComponent.<AudioSource>().isPlaying) return; // don't play a new sound while the last hasn't finished
GetComponent<AudioSource>().clip = voices[Random.Range(0,voices.Length)];
GetComponent<AudioSource>().Play();
Debug.Log ("Timer Ended");
}
displayText.text = minsDisplay + " : " + secsDisplay;
}
//Timer Stop Button
public void GoTimerStop()
{
isFinishedTimer = true;
}
//Timer Start Button
public void GoTimerStart()
{
isFinishedTimer = false;
}
//Timer Settings
public void GoTimerSetting60Sec()
{
timer = 60;
}
public void GoTimerSetting5Min()
{
timer = 300;
}
public void GoTimerSetting10Min()
{
timer = 600;
}
public void GoTimerSetting20Min()
{
timer = 1200;
}
public void GoTimerSetting30Min()
{
timer = 1800;
}
public void GoTimerSetting40Min()
{
timer = 2400;
}
public void GoTimerSetting50Min()
{
timer = 3000;
}
public void GoTimerSetting1Hr()
{
timer = 3600;
}
public void GoTimerSetting1Point5Hr()
{
timer = 5400;
}
public void GoTimerSetting2Hr()
{
timer = 7200;
}
public void GoTimerSetting2Point5Hr()
{
timer = 9000;
}
public void GoTimerSetting3Hr()
{
timer = 10800;
}
}
Your answer
Follow this Question
Related Questions
JavaScript to C# 1 Answer
Jimmy vegas fps tutorial converting to c# 1 Answer
How can I change this java to C# 2 Answers
Help in conversion of variable types c# 1 Answer
convert java to c# 1 Answer