I am developing a game with Unity which has a main menu to allow the user select game mode. In this screenshot you can see an example:
My problem is the following:
I need to create a scroll in which user can put his finger on point 1 and swipe/slide to point 2. On the one hand, while this action is happening the element 2 increase its opacity and its position change progressively to the center. On the other hand, while this action is happening the element 1 decrease its opacity and its position change progressively to the left part of the screen.
Extra information:
The elements are sprites with colliders to detect the selection of the player.
What would you suggest me to do? Have you got any code to solve this? Any other suggestion?
Hey i think i understood your problem,
According to my understanding. You can use a binary tree for this work, u can use a sprite sheet with different level of alpha value. The variable of the binary tree responsible for changing the sprite will depend on the finger's position on the screen which you can easily get by camera.ScreenToWorldPoint(pos). also you can easily change the position of the gameObject by recording the change in initial and final position of the touchPhase.
Related
I have a game in Unity.
The idea of the game is that an object is spawned on the screen.
It exists for several seconds.
You need to click on it, while it exists.
What I want to do, is that while it exists - I want to show a timer, but not with numbers, but with an outlined line on the perimeter of the screen.
I know, how to make a make a slider and how to make circular health bar, yet I do not really have an idea to make a slider, that is decresing from everywhere to the centre as you can see on the screenshots below.
I would be thankful for the inspiration!
This should be a very good fit using alpha cutoff with a custom shader.
Here's a video explaining it in detail (it's only the first half you will need).
The basic idea is to create a texture with a graded alpha depending on how you want the texture to appear/disappear. In this case the alpha value at the top and the bottom would be close to 0 and then gradually around the line on both sides towards the middle increase to 1. The shader then cuts off the texture below a cutoff threshold which you can change depending on the value of the timer.
As a dumb and simple approach:
Have two images with fill, one goes middle towards top the other middle towards bottom.
Just imagine the pnguin is your outline ^^
I'm making what is essentially a board game within Unity 2D. The player will be able to move their pieces along a grid (see below). The larger circular sprites are the pieces, which the player can click on, then click a gridPoint (the small squares) to move to it.
I've created the grid by using empty gameobjects (I've rendered a sprite on them for visual help) at each intersection. These are the points where players can move between. The distance between the points varies, though the horizontal distance is always 1.
The full functionality would be...
A player clicks on a piece,
A preview area of where the piece can move to is shown.
Player clicks on a valid grid point where the piece should move to.
Grid piece moves to new point.
First of all, have I created this in the right way? I need the grid to be accurate, as it will be populated with an accurate sky map. Currently this grid is accurate.
Assuming this is the right way of doing it, how do I, when a piece is selected, work out which grid points are within range? Say a piece can move 4 spaces, then any space 4 grid points away from origin (horizontally, vertically and diagonally) can be moved to. I'd also need to count how many spaces the piece has moved.
I also need to make the piece travel from it's original position, to the new grid point, via grid points using the shortest route.
Any help is appreciated.
OK, there are many solution for this, but let's keep it simple!!
simple overview of your solution step!!
If your grid is fixes size(i.e fix height and width unity length), then put custom placeholder (empty gameobject)in intersection point
detect the swipe detection(assuming you working with this mechanism) from current tapping piece to direction.
using any tween library(i suggest DoTween library from unity asset store, it's free and absolutely amazing.)move your piece to that placeholder.
Now bit more in depth Understanding!!
please refer the below reference.
initial condition of any type of grid
after creating the grid, you can put empty gameobject as an placeholder in between grid(you can make it invisible- i.e make it alpha 0 of image property!)
placeholder in between gap of grid
you can make you piece(player) child of any of these placeholder.
you will detect the swipe or even tap mechanism and check weather in what ever direction you swapping or in which invisible placeholder you tapping, has any child??
if yes, that means that placeholder is already occupied with other piece(player). so no logic to move your current piece. so ignore the swipe.
if no, that means placeholder is empty, so its valid move.
using any tween library, from current placeholder position to desired placeholder, move your piece(player).
after reaching to desired placeholder, make that piece the child of that desired placeholder(using setparent(desiredplaceholder.gameobject.transform.position) kinda code)
and you done!!
hope you find this helpful!!
I am currently working on a game, and i've run into the following problem:
I want to draw some results as a graph on top of my Canvas and so far i've found out that my Canvas needs to be in Screenspace-Camera for this to work, as the LineRenderer is a 3D-Object and will be covered by Screenspace-Overlay otherwise.
And i've actually got it to work with this, looks like the following:
But the problem i've encountered is that if i increase the screen size, e.g. by stretching the GameView or maximizing it, the line disappears, even though it has a negative z compared to all my UI elements and therefore appears in front of them in the EditorView:
If i try to fix this by applying a greater negative z-Value relative to the screen size the lines get distorted, as they are getting closer and closer to the camera, and changing their alignment from view to z-Axis didn't help either.
What makes this even more confusing is that this happen to lines that are drawn lower (smaller y-value) first, meaning a line at the bottom of my graph disappears earlier. I really don't know why this is happening. Any help would be appreciated.
For 3D objects mixed with UI elements I recommend using a separate camera with greater depth than the camera drawing standard ui elements. This way your 3D objects will always be rendered on top of the UI elements and you wont have to worry about Z positions.
I'm working on a game made in XNA,C# and I want to enable xml based animations.
XML will look like this
<Animation>
<AnimatedObject>
<Filename>Spaceship_Jet_01</Filename>
<Flipped>false</Flipped>
<StartPosition_X>300</StartPosition_X>
<StartPosition_Y>500</StartPosition_Y>
<GOTOPosition_X>650</GOTOPosition_X>
<GOTOPosition_Y>500</GOTOPosition_Y>
<Time>10000</Time>
</AnimatedObject>
</Animation>
This will move an object to the side, like this
http://imm.io/odc7 (sorry the X coordinate is wrong)
I noticed there will be problems, when the players display resolution is different from mine because I enter pixel precise information about where the object comes from and where it has to go.
I thought about a grid so I can tell the programm to move the object from (30,27) to (22,27) e.g.. Is this a good solution? The grid has to be independent from the resolution but the number of tiles has to be constant and I have to draw the object to the screen. That means I have to find the right pixle position of the tile at position (22,27) and then "move" the object to that tile.
Is there a better way to do that? How can I solve this with XNA?
If you use a 2D camera you won't have any problem... because calculating the new view to adapt it to the new resolution is not difficult.... and you have not to change anything of your loads methods nor logic...
You can do, but I don`t like
Work with positions in [0..1] range, is difficult to measure.
Fix the position with the new resolution factor when you load the xml... is ugly...
Pos *= NewResolutionSize/DefaultResolutionSize;
The DragCompleted event of a wp7 control has a parameter of type DragCompletedGestureEventArgs that contains the variables HorizontalVelocity and VerticalVelocity.
How are these velocity variables interpreted? I get a value of 0 for a slow drag and a value of >4000 for a fast drag, but I'm not sure how I can relate these numbers into a number of pixels dragged per time interval value.
Background of my question: In my program the user can grab an object and then drag it. I want the object to continue moving (up to a standstill) when the user lets go of the object.
You can't relate them into pixels. But you can create a relative scale according to the velocity, and then how much it should slow down / speed up, based on the velocity.
If you think of the Pictures Hub image viewer, then you can see that you can pan around images, but if you use a high enough velocity, it'll flick to the next/previous image.