Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Farwall · Feb 10, 2017 at 07:24 PM · c#coins

How to move all coin to corner after pickup which looks like coin is moving from 3d space to 2d canvas corner position.

Hi,

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");
     }

alt text

capture1.jpg (46.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Farwall · Feb 14, 2017 at 06:38 AM

OK, I found the easiest solution by @Bijan

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.

I chose #2 and working great. :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Pitiedowl · Feb 10, 2017 at 07:27 PM

Animations have it set on collision play animation. Make the animation of the coin moving to the corner of your choosing

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by PAHeartBeat · Feb 11, 2017 at 11:14 AM

Hi,

Its very simple.

you have two different view view.

  1. One static view Cam (orthographic) for HUD or Menu Screen.

  2. Second Dynamic View Cam (orthographic or prospective) for Gameplay.

Now how to achieve it

  1. when you player collider with coin get word to screen position using Gameplay Cam method. ( Vector3 pos = GPCam.WorldToScreenPoint(<<worldPosOfCoinInGPEnvironment>>) )

  2. use the screen position get world position of to place animation coin. use HUD cam to get world position from screen pos. pos = HUDCam.ScreenToWorldPoint(pos)

  3. generate few coins at that position and give tween to move it to your desired place

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pitiedowl · Feb 12, 2017 at 01:39 PM 0
Share

Wouldnt animations woek also?

avatar image
0

Answer by LostShepherd · Dec 31, 2021 at 06:47 PM

Hi,

Sry am resurrecting this thread here.

I am a newbie building a 2D game for mobile and I have been following this thread, I've been able to manage most things myself until now but this is beating me.

I have two cameras setup as per the attached screen shots.

I have been trying to implement a similar effect in my case an object collision, which creates a scoretext in the UI layer, that then travels to my UI score counter in the top RHS of my screen. Effectively option 2 from above although I trigger based off a scoring collision.

I had been attempting to do this by grabbing the position of the gameplay object at the point of impact, converting the transform position to a screen point via the Gameplay (MainCamera) e.g.

 //On collision
 Vector3 pos = GameManager.GMInstance.GetMainCamera().WorldToScreenPoint(gameObject.transform.position);


Then I was getting a pooled UI text object, enabling it and setting the text value, color and most importantly position based on pos, the pooled items are parented to my Canvas transform. Eventually I wanted to DoTween it to the score counter, but I have not been able to get that far.

I think a big part of the issue is that the initial pool creates objects which are scaled very high e.g. 38.876% with exaggerated coordinates e.g. Vector3(-388.999939,-1320.547,-3683.23853). I think this might be the point where the UI Camera lives, I am not sure if this is because I have the pooling script attached to a UI panel in the canvas?

I could be going about this all wrong I'm not sure, but I've tried a few things and not had much luck. I'm not sure if that is the best way to pool UI elements i.e. attached to the canvas, but as I could have up to 100 items repeatedly colliding on screen I do not want to create and destroy UI elements.

Any advice or ideas as to why I am not cracking this would be much appreciated.

Thanks, LS

@PAHeartBeat @Farwall


uicamera.jpg (125.0 kB)
maincamera.jpg (99.3 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LostShepherd · Jan 01 at 09:43 PM 0
Share

Got sorted this thread really helped

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Rewarded ads don't give rewards 0 Answers

Need help with using Player Prefs to save number of coins collected. 1 Answer

Making a bubble level (not a game but work tool) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges