Coding to moving and arenging

Hi
I want to code for a game like these pictures in this way : when player randomly taps on a gameobject , it should go to upper right . And when player taps on another gameobject it should go under the first one , up to the end .
Thanks





?

You’re not very clear about what part of the script you don’t know how to do. Have you tried anything? If you have, what did you try, and where did you get stuck? What is your scene set up like currently?

If there’s a more specific question you have, you can post that, you’ll get better answers.

If you want someone to write the script for you (which is what your post reads like), I recommend finding someone on Unity Connect to hire to do so. Most of us here are happy to help you learn to code and instantly shut down if you act like you just want us to write it for you, hence no responses.

1 Like

Thank you for your answer
I really want to learn. I am amateur in unity and coding . I didn’t find a perfect source to explain all codes (also my English language is not perfect ) .
I can write code like this :

    if (Input.touchCount > 0) {
            Touch touch = Input.GetTouch (0);

            if (touch.phase == TouchPhase.Ended) {
                RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint ((touch.position)), Vector2.zero);

                if (hit.collider != null && hit.collider.gameObject.name == "num2") {

                    xspeednum2 -= 0.8f * Time.deltaTime * speed1;
        yspeednum2 += 0.04f * Time.deltaTime * speed2;
        num2vec = new Vector2 (3.2f + xspeednum2, -2.42f + yspeednum2);

        num2.gameObject.transform.position = num2vec;
                }

I need to code about 3 points . How to down size gameobject along the way. How fix it to right places . And how to define that the second chosen goes to second place. I might can code it but it take several days and it won’t be efficient. My first game is a simple game but it has more than 30000 line code!

1 Like

upload full code

Great, now we’ve got something to work with.

So I’ll give you a bit of code here that’s very handy:

IEnumerator ScaleOverTime(Transform t, Vector3 startScale, Vector3 endScale, float duration) {
for (float t=0f; t<duration; t += Time.deltaTime) {
t.localScale = Vector3.Lerp(startScale, endScale, t/duration);
yield return 0;
}
t.localScale = endScale;
}

//when you want to start it changing scale
StartCoroutine(ScaleOverTime(transform, Vector3.one, 0.5f * Vector3.one, 1f);

This will change the scale gradually across (duration) seconds.

This function can be tweaked and altered to do basically anything over time. If you want to add a couple of parameters for start and end position, and a line before the “yield” line, you could make this smoothly change the object’s position at the same time, as well. I think it’s best for your learning if you try to add that yourself, but let me know if you have trouble working it out.

Don’t worry about efficiency until after you’ve got stuff functional! :slight_smile:

1 Like