I am making a game using the Monogame engine and I just need help on one part of my code. Now, every time the character dies in the game, the code just ends. this is because of these lines of code.
else
{
System.Environment.Exit(0);
}
if(y < 0)
{
System.Environment.Exit(0);
}
Now I want the game to have a 'game over' screen every time a user collides with one of the obstacles and this screen will allow you to go to the menu and allow users to play again. the classes I have at the minute is the game1.cs class, the character class and the obstacle class. Thanks for all your help.
You're going to want to keep track of the game state. As an example -- you might only have two states "Playing" and "GameOver". Instead of exiting in your code snippets, set the game state from "Playing" to "GameOver".
Now in the Update call -- you'll want to check for user input during GameOver and allow them to exit the game completely or start a new game.
In the Draw call -- you'll want to check the game state to decide what to render to the screen.
Related
Hello I have the Problem that the Animation Pos not stay. I need this for a Dodge(Combat) system. Root Motion Doesn't work!
.
You can make another state in animation and make your animation to go to that state. In script don't let player move when animation is in that state.
Return to idle state whenever you want to make things normal again.
Other way to do is use other animations libs (like leantween) and make a callback after animation ends.
Halo guys, I'm literally new to C# on Unity. Can I ask some scripts if I may to you all. The case is somethings like this: I have an animation that played some sprites on a scene. I want to know if I can skip / forward the animation by touch using C# scripts placed on Empty Game Object. So the animation can move forward for 1 second / 2 seconds if the user touch the screen, so the animation more faster done playing or the user doesn't need to wait the animation that played to be finish.
I just think I may build that function with for statement and placed on void update. Please correct me if I'm wrong, and if I may put some code on you'r thought. Many thanks and cheers :).
I have a game I am making where I want that the player has no animations until it hits a certain trigger. Then I want a short animation to be played, then it will stop the animation again.
To get this effect I have the above animator state machine attached to my player, and when the player collides with the trigger it plays the Halfway animation, then it goes back to the empty state. All of this seems to work fine at first but while my player is in this empty state loop thing, I cannot move it. I am using "rb.velocity = new Vector3(stuff);" to move my player, and when I disable the animator component I can move fine. I was wondering if
There is any way to enable movement while I am in this empty state,
There is some way to get rid of the entry transition entirely so I don't have to have the empty state at all, or
Pretty much anything else that would make this work :P
If you need more information let me know, I will try and help you help me as much as I can. Thanks!
My question is, how could I hide a GameObject when it is not being rendered by the camera, but to unhide it when it comes back into the camera view?
My code is the following:
void Update () {
if (renderer.isVisible) {
objectToHide.renderer.enabled = true;
}
else {
objectToHide.renderer.enabled = false;
}
}
The problem is, the object becomes hidden, so it can't be detected and unhidden.
Any help is appreciated!
(The goal is simply to speed up the FPS and improve game performance)
Your answer is simple. The game only renders the objects in camera sight. You can hide an object or even disable the renderer component but its not used for memory management or better process.
There are standard techniques for making a game run more effient. One of them is LOD or LEVEL OF DETAIL. You have a model with different polycounts and different texture resolution. When its near you use the highest polycound and highest texture resolution for further distance you use lower options.
Another technique is level streaming. If you have a big level and you want to game run on low memory or don't make players wait for long time for level loading, you have to do this. If you search a little you can find lots of information on different engines.
Most recent games have an option to choose foliage detail or environment detail. You can make a layer for every level of detail of your game and for every level of option player made you destroy those objects. Maybe I'm wrong but renderer.enable cant be good because the object still is in game and game just doesn't show it. You have to change many components to make it work and controlling all of them is hard.
To improve performance, you better try to destroy scripts and gameobjects as soon as they are not needed. Like bullets coming out of the game board, scripts that run just once and already finished, ...
For instance, consider a brick breaker game where once the ball falls below the paddle, the user would get a displayed message (using SpriteFont) asking whether he would like to play again. If that condition was met,and the sprite font stated 'Play again, enter 'y' for yes, 'n' for no' how would one proceed to take that input in XNA?
Well, first you're gonna want to have a boolean to see if the game has ended or not. If you didn't have the boolean then the user could press Y or N anytime and the game would restart.
It should be simple to setup one anyways, just have it detect when the ball falls below the paddle and set the bool to true;
Then, the rest should be quite simple to figure out.
if (gameRestart)
{
if (Keyboard.GetState().IsKeyDown(Keys.Y))
{
// code for restart goes here
}
else if (Keyboard.GetState().IsKeyDown(Keys.N))
{
// do nothing, I guess?
}
}
Here is a tutorial on detecting key presses in XNA: http://msdn.microsoft.com/en-us/library/bb203902.aspx