androidiosuser-interfaceunity-game-enginemeter

How to make coins fly toward coin meter like Temple Run unity


Can anyone help me to fly coins toward the coins meter.

I have try this code.

 public GameObject meter;

 void Update () {

     transform.position = Vector3.Lerp(transform.position, meter.transform.position, 1.5f * Time.deltaTime);

 }

But it's not working for me. Maybe because the CoinsMeter is UiImage with text in my case. So please help me to solve this.


Solution

  • Use a dummy gameobject behind your coin meter and set your coins' Target position to that dummy gameobject position.

    Edit:

    Since your camera position might change, the above one doesn't work in such cases. Do like,

    Vector3 target = uiObject.transform.position + offset;
    Vector3 worldPoint = Camera.main.ScreenToWorldPoint(target);
    

    Now, worldPoint is your new target position.