Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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;
     }
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

39 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges