Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move all coins from 3D space to a corner of 2D canvas

I am trying to make a game like temple run 2. I want the same effect as stated in question and as attached screenshot. I tried with Animation its working when I animate the coin to center top but no luck with top left corner. Please Help. Thanks

Here is code:

if (col.gameObject.tag == "500") {
    score = CryptograpicEncryption.GetInt ("ScoreKey") + pick500;
    CryptograpicEncryption.SetInt ("ScoreKey", score);
    ScoreCount.text = "Cash Collected: " + CryptograpicEncryption.GetInt ("ScoreKey").ToString ();
    col.gameObject.GetComponent<Animator> ().SetTrigger ("openNote");
    col.gameObject.transform.GetChild (1).GetChild (1).gameObject.SetActive (false);
    col.gameObject.GetComponent<Animator> ().SetTrigger ("highLeft");
}

enter image description here

like image 931
Jamshaid Alam Avatar asked Oct 21 '25 01:10

Jamshaid Alam


1 Answers

It depends on your game but here are some options:

  1. Add an empty gameobject to your character and carefully set its position so that it always be positioned behind the desired ui object. Then move the coins from 3d space into the 3d space position of the game object.

  2. Remove the coin as soon as the player get it, then create an identical coin using UI.Image in its place (in 2d space of canvas) immediately moving to the corner of canvas. You can convert 3d space position to 2d using 2dPosition = Camera.main.WorldToScreenPoint(3dPosition)

  3. You can calculate the 3d position of the corner of the canvas using 3dPosition = Camera.main.ScreenToWorldPoint(2dPosition) and make the coins follow that location. But the location changes overtime as the camera moves so you should recalculate it every frame.

like image 94
Bizhan Avatar answered Oct 23 '25 15:10

Bizhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!