Rxanadu

Anyone here know Unity well?

Recommended Posts

I've been trying to create a main menu where

  • the menu box appears
  • slides (slowly) to the center of the screen
  • slides (slowly) out of view when the player presses an item in the box

However, whenever I try to find out how to do this (let alone anything about how to do things in Unity), I was met with little to no simple tutorials or correct tips on how to do anything relative to this. This is especially true when visiting Unity Answers; there's little to no help from YouTube, as well.

So, does anyone know how to do what I wan to do? I've already tried using Time.deltatime to move the box slowly (i.e. not snapping to the new position when a button is pressed), but then the box just stays at the second position after the button is pressed.

I've attached a .zip file with a C# file with some code I found online that I've been modifying to allow for the same function I mentioned above, but I just don't know what else to do.

MainMenu.zip

Share this post


Link to post
Share on other sites

Quite a lot of the guys on my forum are very experienced with Unity, see my signature if you feel like asking there. :tup:

Share this post


Link to post
Share on other sites

Is that the actual code, or just what you found? I.e. it might be helpful to just post what you got.

Share this post


Link to post
Share on other sites

Is that the actual code, or just what you found? I.e. it might be helpful to just post what you got.

It's the code I've been working on. It's not 'tweening' (i.e. the box is not sliding into place, but snapping into place).

Share this post


Link to post
Share on other sites

Disclaimer: I know very little about coding, but I am trying to learn.

I think it's currently snapping into place, because even though you do the += 5.0f, it does it so quickly you can't really perceive the translate. So taking that float and multiplying that times Time.deltatime would be the solution to that. I think as a rule, you'll want to use Time.deltaTime: "If you add or subtract to a value every frame chances are you should multiply with Time.deltaTime. When you multiply with Time.deltaTime you essentially express: I want to move this object 10 meters per second instead of 10 meters per frame." Otherwise the speed of something is dependent on how fast your processor is.

If you multiply by Time.deltaTime and the box moves into view, if you press space again and it doesn't move, I'd say there is something wrong with the 'else if' part of your loop?

I know someone here knows what's up.

Share this post


Link to post
Share on other sites

I haven't looked at the code, but yeah, if you're just doing that stuff in a code loop, it'll happen instantly. You only want to move the thing every few milliseconds. How that's done depends on whatever you're working with.

Share this post


Link to post
Share on other sites

I haven't looked at this thread, but yeah. What PiratePoo and toblix are saying is true.

Share this post


Link to post
Share on other sites

ZOVYR.jpg

Hahaha oh god. The mouths as eyes thing never gets old.

Share this post


Link to post
Share on other sites

It looks like your box will only animate when the space key is being pressed down. Also, I think I see why your box seems to snap to the location - you have a loop in AnimateGui that runs completely in one frame, so in one frame it moves from -200f to 20f. What you should have instead is only one statement changing the value of myBoxLeft that executes in any one call to AnimateGui; combine that with the deltaTime trick mentioned earlier, and you should be fine.

Instead of using the position to indicate which direction the box should be moving, I'd probably use a boolean, as well, but that's your decision.

Share this post


Link to post
Share on other sites

Why use animations when you can just lerp the object to it's destination? Unless you need to finely control when something arrives at it's destination I kinda find using the animation system a serious pain.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now