Search Unity

Animations are (obviusly) affecting the instantiate position

Discussion in 'Scripting' started by impheris, Jul 11, 2019.

  1. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,670
    Hi and good day...

    i know this is a weird or noob question but i really do not know how to fix this.

    I need to instantiate an object with a random range in x and y but with a loop animation on x (and with the random range on x too)

    I have an object that is instantiating other object with this code:

    Code (CSharp):
    1. CloneA = Instantiate(DesctA, new Vector3(Random.Range(-2, 2), Random.Range(3, 1), -1), Quaternion.identity);
    Where "DesctA" is a public GameObject (a cube)

    What i need to do is to instantiate that cube in those random ranges but with a simple horizontal animation loop

    how i can do it?

    Thank you guys and sorry for my english
     
    Last edited: Jul 11, 2019
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    What you need are two steps:
    1. instantiate the object at the starting Position
    2. During Update() move the object to the Destination.
    So far, you have only given us one of the two (starting position or destination). Where do you want to move the object to? You may then want to Google 'Unity slowly move object" for a lot of great tutorials.
     
  3. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,670
    Hi Thanks but i do not know how to code that, i was looking on google but i did not find any help in my situation.
    I will put more details on the main post
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Is your animation setting the x-position of the object? Is your animation made in the Animation window in Unity?
     
  5. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,670
    Q
    Is your animation setting the x-position of the object?
    A
    Yes

    Q
    Is your animation made in the Animation window in Unity?
    A
    Yes, i do not know how to animate with scripts