"Unity3d self-study record" Unity3d's homemade small clock

Source: Internet
Author: User

Today to write a small clock, in fact, very easy, applied to the Euler angle.

First create clocks, minutes, seconds, and 4 points (12, 3, 6, 9) Lazy ~ ~ did not make so many points.

Clocks, minutes, seconds the center of the three parent must be aware that we are rotating the Euler angle of the parent.


(The center of the parent is at the vertex of the child)

Next we'll write the code. For example, the following:

Using unityengine;using System.collections;public class Clock:monobehaviour {public    Transform shi;    public Transform Fen;    Public Transform miao;//with this for initializationvoid Start () {}//Update is called once per framevoid update () {
   
    debug.log ("Time" +system.datetime.now.hour);        Debug.Log ("min" +system.datetime.now.minute);        Debug.Log ("Seconds" +system.datetime.now.second);        Second        float miaonum=system.datetime.now.second*6f;        Miao.eulerangles = new Vector3 (miao.position.x, MIAO.POSITION.Y,-miaonum);        Min        Float fennum = System.DateTime.Now.Minute * 6f;        Fen.eulerangles = new Vector3 (fen.position.x, FEN.POSITION.Y,-fennum);        Hours        Float shinum = System.DateTime.Now.Hour * 6f;        Shi.eulerangles = new Vector3 (shi.position.x, SHI.POSITION.Y,-shinum);}}
   

all the values are *6. Because altogether 60 seconds, one lap is 360 degrees, 1 seconds is 6 degrees.

It's easier to write.

Let us not laughed at.


"Unity3d self-study record" Unity3d's homemade small clock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.