Unity realizes Big Carousel notes

Source: Internet
Author: User
Tags diff

1, unity in order to achieve the rotation of a gameobject, we need to change its transform under the corresponding rotation, because our big turntable is a 2D angle of view, so we first need to clear the direction of rotation of the big turntable is rotating rotation Z.

2, how to realize the big turntable from rotation to slow, and then to the rotation of the designated position to stop. View the Unity script to find the following methods to implement the rotation of the large turntable as follows:

Public void Rotate (Vector3 eulerangles, Space relativeto = space.self);

applies the angle of rotation of a Euler angle, eulerangles.z degrees around the z-axis, eulerangles.x degrees around the x-axis, eulerangles.y degrees around the y-axis (in this order).

Span style= "line-height:21.6000003814697px" >public void  rotate ( Vector3 axis , float   angle ,  space  RelativeTo  = space.self);

rotates the transformation around the axis axis in angle degree.

public void  rotatearound ( vector3 point ,  vector3  axis angle );

In a nutshell, the rotation of an object at some point in the world's coordinates, by how many degrees

3, for rotation view Unity script know that the above methods are required in void Update (); So we implemented the Void Update () method:

Whether to click the Start button

if (M_isstart = = True)

{

             m_cstartbutton.m_curstate = cguiadvancedbutton.advancedbuttonstate.disable;// Current Start button status is disabled

             m_ftime + = time.deltatime;//Time Timer cumulative
             m_fvelocity = k/m_ftime;//Playback speed (we use inverse scaling functions to achieve fast-to-slow effects)
            &NBSP;IF (m_ fvelocity<=1)
             {
              &NBSP;&NBSP
                 float value = (m_iid*36.0f);//The stop specified here for my project Local
                 float diff = M_gratepin.transform.eulerangles.z-valu e;//current rotation gameobject Euler angle
                 if (Mathf.abs (diff) <=50)// Slow deceleration if the rotated gameobject and the specified stop position is less than 50 degrees
                 {

Using spherical interpolation allows the rotating gameobject to move slowly to the set position.
quaternion quaternion = m_gRatePin.transform.rotation;
M_gRatePin.transform.rotation = Quaternion.slerp (quaternion, quaternion.euler (0, 0, value), time.deltatime);

if (m_gRatePin.transform.rotation = = Quaternion.euler (0, 0, value))
{
M_isstart = false;
M_cstartbutton.m_curstate = CGUIAdvancedButton.AdvancedButtonState.Normal;
M_ftime = 0;
m_fvelocity = 36.0f;
}
}
Else
{

                   //rotation (-1 = right)

                     m_gratepin.transform.rotate (Vector3.forward, ( -1) * M_fvelo City);
                 }
             }
             else
             { //rotation (-1 for right)
                 m_gratepin.transform.rotate (Vector3.forward, ( -1) * m_fvelocity);
             }

}

4, in addition to the use of rotary gameobject to achieve large turntable rotation we can also use the animation to achieve the following:

if (M_isstart = = true)//Whether you click the Start Draw button
{
M_cstartbutton.m_curstate = CGUIAdvancedButton.AdvancedButtonState.Disable;
M_ftime + = Time.deltatime; Timer
if (M_ftime > 1/m_fvelocity)//Determine if the current time has reached the time when a frame is played
{
M_ftime-= 1/m_fvelocity;
if (m_fvelocity<=8f)//Determine if the speed is less than a certain value (set according to your needs)
{
if (index = = m_iid)//Determine if the currently playing frame is background control data, stop playing and erase the data if it is
{
M_gratepin.getcomponent<spriterenderer> (). Sprite = M_ssprites[m_iid];
M_isstart = false;
m_fvelocity = 60.0f;
M_ftime = 0.0f;
M_ftimemeter = 0.0f;
M_icount = 0;
M_cstartbutton.m_curstate = CGUIAdvancedButton.AdvancedButtonState.Normal;
}
Else
{
1/m_fvelocity indicates how long it takes to play a frame
if (index = = m_ssprites.length-1)//If the current frame number is indexed to the last frame, the next frame to play is the first frame
{
M_gratepin.getcomponent<spriterenderer> (). Sprite = M_ssprites[0];
index = 0; Reset Index
m_icount++; Number of statistics laps
M_fvelocity/= 2; Slow playback frame Speed
}
Else
{
If it's not, continue playing the next frame.
M_gratepin.getcomponent<spriterenderer> (). Sprite = M_ssprites[++index];
}
}
}
else//does not reach the specified circle and continues to play the next frame
{


if (index = = m_ssprites.length-1)
{
M_gratepin.getcomponent<spriterenderer> (). Sprite = M_ssprites[0];
index = 0;
m_icount++;
M_fvelocity/= 2;
}
Else
{
M_gratepin.getcomponent<spriterenderer> (). Sprite = M_ssprites[++index];
}


}
}
}

5, in fact, there are a lot of methods, such as the use of Unity's own animation system can also be achieved, the notes summarized here.

Unity realizes Big Carousel notes

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.