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 /
avatar image
1
Question by KnightRiderGuy · Dec 07, 2015 at 06:13 PM · uitimer-scriptjava to c#clocktimers

Clock Script From Java to C# Help

Can someone with a lot more conversion experience please change this Java script to C# Also if you can make it so that it uses the new UI text VS the On GUI text that would be great. I have points to award to whoever helps :)

 #pragma strict
  
 var ClockText  : GUIText;  // Hierarchy DRAG E DROP over var GUI Text in Inspector  
 var ClockDateText  : GUIText;  // Hierarchy DRAG E DROP over var GUI Text in Inspector
 var ClockSecondsText  : GUIText;  // Hierarchy DRAG E DROP over var GUI Text in Inspector
 private var dt = Date();
   
   
 function Update () {
   
 var day = dt.Now.Day;
 var month = dt.Now.Month;
 var year = dt.Now.Year;
 var hours = dt.Now.Hour;
 var minutes = dt.Now.Minute;
 var seconds = dt.Now.Second;
   
 ClockText.text = hours + ":" + minutes;
 ClockDateText.text = day + " " + month + " " + year + " ";
 ClockSecondsText.text = seconds + " "; 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whaleinthesea · Dec 07, 2015 at 07:38 PM

Here is the code, just assign your UI Text elements in the inspector:

 using UnityEngine;
 using System.Collections;
 using System;//you need to import this if you want to use DateTime
 using UnityEngine.UI;
 
 public class UITimeShow : MonoBehaviour{ //feel free to change the name of the class to whatever you want
     public Text ClockText;
     public Text ClockDateText;
     public Text ClockSecondsText;
 
     void Update()
     {
         //Get the time
         int day = DateTime.Now.Day;
         int month = DateTime.Now.Month;
         int year = DateTime.Now.Year;
         int hours = DateTime.Now.Hour;
         int minutes = DateTime.Now.Minute;
         int seconds = DateTime.Now.Second;
 
         ClockText.text = hours + ":" + minutes;
         ClockDateText.text = day + " " + month + " " + year + " ";
         ClockSecondsText.text = seconds + " ";
     }
 }

EDIT: if you are using stripping in Unity, make sure you add this to link.xml:

 <linker>
        <assembly fullname="System" preserve="all"/>
 </linker>
Comment
Add comment · Show 4 · 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 KnightRiderGuy · Dec 07, 2015 at 07:43 PM 0
Share

@matyboy02 Not GUI texture UI text.

avatar image whaleinthesea KnightRiderGuy · Dec 07, 2015 at 07:48 PM 1
Share

Sorry, I changed the code. Now it should work.

avatar image KnightRiderGuy whaleinthesea · Dec 07, 2015 at 08:24 PM 0
Share

@matyboy02 Thanks man that was awesome, you have no idea how long I have been chasing after someone, anyone to do that little job for me, god its like pulling teeth out of a dead horses head on here sometimes trying to solicit help from the proverbial "Boys Club" :) Can't tell you how much I appreciate that man. 100 points going your way :D btw what is that:

  <linker>
             <assembly fullname="System" preserve="all"/>
      </linker>

stuff about?

Show more comments

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

40 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 avatar image

Related Questions

Unity 5 - Time counter Up script (millisecond precision) UI 1 Answer

How Would I Change This To Read Within A Time Range? 1 Answer

How Can I make a Timer With The New UI System? 1 Answer

Timer reset 1 Answer

Minutes and Seconds in a text 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