Time boiled rain Unity3d let the object move ③-ugui dotween&unity native2d Realization

Source: Internet
Author: User

This article first bull, the second blog park. After the first series, the second , this article for the third chapter, thanks again "armed Sanzang" in the first two selfless and wonderful questions answered

Write in the front, time to boil the rain, in order to miss

The following references roost read some of the tutorial articles

In fact, these 3 kinds of animation have its specific use occasions.

The first animation is ideal for creating simple object displacements and property changes of immediate nature (in later tutorials, I'll dig deeper into the potential of storyboard animations and dynamically create more complex keyframe-based keyframe animations).

The second animation is suitable for changes in the global properties, such as the relative displacements of the enemy or NPC and the map, as well as the changes in the properties that we want to refer to later.

The third type of animation is ideal for use in spirit (character) animations, such as the movement of characters, battles, and spells.

Summary: The previous three respectively explained the storyboard animation, CompositionTarget animation, dispatchertimer animation, and transverse analysis of different occasions corresponding to different animation application mode, these will constitute wpf/ The basis of the Silverlight game engine.

Here are three types of animation can be likened to the Unity3d,

The first, the various moveto (Vector3,duration) based on Dotween, or the direct movement of the first article;

Second, update-by-frame updates based on update;

The third, fixupdate-based timing update, such as the one mentioned here may be a physical collision, or a timer similar to the custom timers (next analysis).

These things are lower level, need to understand the difference between fixupdate and update, and the relationship between UI thread and non-UI thread (the concept of DispatcherTimer in WPF)

This piece of stuff is a bit deep, I also dare not to describe, whether the right has a master passing, can dispel doubts. List of two reference articles for extended reading

Difference between Update method and Fixedupdate in Unity?

The difference and application of timer and DispatcherTimer in WPF

These three forms of animation, many people know, but how to use and differences, but in the blog is not mentioned.

Here are the references listed here only for nostalgia.

Background

The first two are relatively basic, the use of some basic knowledge, in fact, there are some early Daniel packaged plug-ins and tools, do not have to repeat the production of wheels. However, the various packages are inevitably functionally overlapping and may be used differently, which may be something we need to pay a little attention to. This article mainly listed under the Dotween plug-in Ugui Direct mobile and unity native2d realization of mouse click-to-frame movement of the function, about the two plug-ins and functions are no longer detailed, because there are some tutorials, if you want to learn their own search. The picture's still the same.

Achieve a

Based on the Ugui translation of Dotween, here it is calculated that the next duration may not be welcome, the code is as follows:

Using unityengine;using system.collections;using unityengine.ui;using DG. Tweening;public class Panelcontollerdotween:monobehaviour {//Use the-initialization public    Image sprite;    Private float speed=2;void Start () {   }//update is called once per framevoid update () {        if (Input.getbutton (' Fire 1 "))        {            //the coordinates written here are pixel coordinates, which is the meaning of screen coordinates (smaller than world coordinates)            Vector3 mouseworldpostion = input.mouseposition;// Camera.main.ScreenToWorldPoint ();            float duration = vector3.distance (mouseworldpostion, sprite.transform.position)/speed * application.targetframerate;            sprite.transform.DOMove (mouseworldpostion, duration). Setease (Ease.linear);}}}        

  

Implementation two

This piece to say a little bit, see a lot of tutorials are generally single talk Ugui or single talk natvie2d, very few have used together, here own experiment under, directly build a scene and Ugui together to use can, relatively simple, dark box is I give the panel set color to facilitate the difference, It is found here that the two can coexist well, as follows:

The code is as follows:

Using unityengine;using System.collections;public class playercontroller:monobehaviour{private Vector3 Currentposito    N    Private Vector3 movedirection;    Private float speed = 2;    Private Vector3 Targetpositon;    Vector3 Mouseworldpositon = Vector3.zero;    Use the this for initialization void Start () {movedirection = Vector3.right;        }//update is called once per frame void Update () {Currentpositon = transform.position; Is the left mouse button click if (Input.getbutton ("Fire1")) {Mouseworldpositon = Camera.main.ScreenToWorldPoint (inpu            T.mouseposition);            Movedirection = Mouseworldpositon-currentpositon;            movedirection.z = 0;        Movedirection.normalize (); }//debug.log (String. Format ("X1:{0},y1:{1},z1:{2},x2:{3},y2:{4},z2:{5},d:{6}", Mouseworldpositon.x, MOUSEWORLDPOSITON.Y, Mouseworldpositon.z, currentpositon.x, Currentpositon.y,currentpositon.z, Vector3.distance (MouseWorldPositon,(Currentpositon)));            if (Vector3.distance (new Vector3 (mouseworldpositon.x,mouseworldpositon.y,0), Currentpositon) > 1) {            Targetpositon = movedirection * speed + Currentpositon;        Transform.position = Vector3.lerp (Currentpositon, Targetpositon, time.deltatime);        } else {transform.position = Targetpositon; }    }}

  

Here is left a small problem is about moving a certain point of judgment, here I simply use a distance of two points small with some absolute value to do, but in the natvie2d found that the movement is jumping, mainly coordinate system unit problem, if there are experts passing can help provide better methods.

Summary of issues

According to three of the study, this is a relatively large harvest, especially through this study, found in the previous article encountered problems, mainly

1, mouse click on the coordinate problem?

2, is about the vecotr3.lerp interpolation problem

If a careful friend might find 2 functions I ugui in the comments.

Camera.main.ScreenToWorldPoint (input.mouseposition)

Vector3.lerp (Currentpositon, Targetpositon, time.deltatime);

The main problem is actually in the coordinate system value, Ugui specifically made an optimization, the use of the 2D World screen coordinate units are pixels, the value is very large, and native2d use 3D World coordinate systems units are floating point hundred points, so there are differences in conversion and use.

This article also left a problem, is Ugui and native2d mouse event occlusion problem, now see the phenomenon is mouse events can be traversed, this problem wait until later to solve it.

Time boiled rain Unity3d let the object move ③-ugui dotween&unity native2d Realization

Related Article

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.