Hey guys, I really new to unity and had a question about my button.
I´ve added a joystick which only controlls my player in the horizontal axes and wanted to implement a jump button. My JumpScript ist currently like that:
jumpscript
The problem is, that the player can jump as much as he wants and this is not what I want. How do I make a groundcheck ?
picture of my game
Put a collider on your players feet and jump only OnCollisionStay with the ground. It should do the trick. Like in here Unity 3D: How to stop being able to jump in the air
Related
I have a mobile game with a simple mechanic where player must touch screen to jump. Problem is, if player clicks pause button, character jumps as well. I need to prevent this.
I came up with an idea of creating a square without sprite renderer and cover the area that I want to prevent from click and simply give a layer to that square so I can control if player is not clicking that layer, then jump.
How do I achieve this? Any help would be appreciated.
Thanks a lot.
I'm currently making a game in which I do not plan on adding any physics to the player. Player will be moved simply by modifying the position and rotation directly through code on a grid. Should my player be a Game Object instead of a Rigidbody? Or something else entirely? I'm a little new to Unity and don't quite know what would be best for the player.
Your player is always a GameObject, your player can't be of type RigidBody If i understand your question right you want to know if it's better to use a RigidBody or a custom script tomove your player ?
For easier use, if you are new to unity i would advice you to use the Rigidbody. You simply disable the gravity on it. If you go for a custom GameObject it's going to be more flexible but you will have more work to do (like collisions, movement calculation, etc...). You can disable the gravity on a Rigidbody with "useGravity = false" via code or in the inspector.
If you want to make your own script:
Here is a video than will explain how to do it: https://www.youtube.com/watch?v=AiZ4z4qKy44&t=246s&ab_channel=Comp-3Interactive
else:
Rigidbody Docs: https://docs.unity3d.com/ScriptReference/Rigidbody.html
Hope it help. Have a nice day !
i am doing a tutorial for making a basketball game on unity. (https://www.udemy.com/share/101uUY3#-3V6juuSNcls89IERileIvuAAnAKmHT1RZLywggv58TF_aJfcALyzHoWC3bpgzklCA==/)
when i make the ball, it floats, and it doesn't fall, and in the tutorial they say to make it a RigidBody to make it fall, and to make it move when i touch it. well, it helps with falling, but when i touch it, i just go on it like it is a staircase
anther piece of information that i think is important: in the tutorial they use the old first person view(fpsController) through assets>import package>characters. but unity removed that, and they say in the internet that i should download the new first person controller from here: https://assetstore.unity.com/packages/essentials/starter-assets-first-person-character-controller-196525 and i changed the default PlayerCapsule scale to 0.001, 0.001, 0.001 and turned off "casting shadows" because i didn't want the capsule to be visable
p.s: this is my first question on stack overflow, and my first project in unity, so if i did somthing wrong, please tell me.
I made a button that is clickable during the game playing. As I want the button have a fixed position in the main camera, I made both the main camera and the button children of the player gameObject so that the camera will follow the character while jumping or moving, everything works fine but there also a border colliders which will prevent the character moving out of the playing area. But then the collider of the button which was made intend to make the button clickable will also collide with the border which will prevent the character moving right forward. If we set the collider of the button a trigger, it seems that the button will be triggered wherever I click the mouse on the screen, that's not what I wanted.
I know maybe I could prevent this by checking if the collided object is the button or the character, but is there a better way to do that? Thanks.
For a 2D platform game, I would add a 2D user interface in a canvas over the "map" (the layer where you have the gameobjects like the character, platforms, enemies...). So the button will be always in the same place of the screen and will never collide with any gameobject of the game.
You make take some ideas from here: https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-events-and-event-triggers
Try use new UI in Unity may it fix your issue:
https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-button
I am trying to make a game in unity, and I am new to unity and coding, and I have started making a game, I have made some progress on it but I am having trouble finding some of my answers on youtube and the unity forum, and sometimes when I do, I still can't get things to work. So this is what I'm trying to do.
I have a map and the player is on top of the tower, I want the player to fall and when hitting the ground, dies with it displaying game over, What could I do to make this happen and what script?
So i have this now,
// Ground.cs: Kills players that touch this.collider.
using UnityEngine;
// Attach this to the grass collider
public class Ground : MonoBehaviour {
// Called when another collider hits the grass.
// This is part of Unity!
void OnCollisionEnter(Collision c) {
// Does the other collider have the tag "Player"?
if (c.gameObject.tag == "Player") {
// Yes it does. Destroy the entire gameObject.
Destroy(c.gameObject);
}
}
}
Now, I need to it transition to a game over overlay, which asks me to restart, yes or no.
The resources are out there in regards to learning Unity3D efficiently.
Look at the Unity3D tutorials: https://unity3d.com/learn/tutorials
These tutorials are usually kept up to date in terms of not using deprecated code. Additionally, several of the tutorials will teach you how to set up events like those that you need.
In regards to your immediate question though, look into forming the logic for your game.
You're going to need allow your player gameobject to fall via either gravitational force enacted on a rigidbody or hard-coded physics being applied to the gameobject. Next you will need to determine if the player gameobject has collided with the "floor". If so you will need to trigger an event to destroy the player gameobject, then display a GUI Text that says Game Over.
Look around more at tutorials and get better acquianted with Unity. Over time, you'll learn how to make things happen. If you have more questions, feel free to ask.
Answer to you update:
If your code is functioning correctly and your destroying your gameobject correctly, then awesome! You're learning fast!
The next step could be:
Create a Canvas, create a gui panel, create a gui text
That gui text object can have your Game Over Text
Now, create a button that you will utilize as the restart button
You can have the button call a function which utilizes SceneManager.LoadScene to reload the scene. Look here for an example: http://answers.unity3d.com/questions/1109497/unity-53-how-to-load-current-level.html
Next, Disable the panel as you will not need it until your player dies.
When your player collides with the ground you will destroy the player gameobject and set the panel you created to active. (you can trigger these actions via a listener in code or via the button component in the inspector).