Unity2D | Complete C # Unity Developer | Game Engine library
kandi X-RAY | Unity2D Summary
kandi X-RAY | Unity2D Summary
Complete C# Unity Developer 2D: Learn to Code Making 2D games.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Unity2D
Unity2D Key Features
Unity2D Examples and Code Snippets
Community Discussions
Trending Discussions on Unity2D
QUESTION
I am a bit nooby when it comes to unity. I have no clue where to start with grids. What I am trying to do is make a grid where each gridspot stores all of the gameobject within it in a list/array. Then those same objects can acces that list if they are looking for somthing. Anny suggestions where I can find what I am looking for?
Edit: This is a 2d game but the unity2d tag is showing med unity3d
...ANSWER
Answered 2022-Mar-08 at 00:20You can create gridManager class that has 2d array of type gridCell class
QUESTION
I am trying to set a score for the whole game in Unity2D, but it only saves it for one scene, then it comes back to 0 for the next scene. My game has 16 scenes and I need to score to be a total score instead of one score per scene. Is there a way to save the score for the whole game?
Here is the code. I also tried using DontDestroyOnLoad but it keeps resetting the whole score. Please assist me. I also need this for my coin system, to keep the coin count, the coin code is below.
...ANSWER
Answered 2022-Feb-05 at 09:22Use PlayerPrefs, as you use it for storing the highest score. Also, you have a strange behavior of your highest score logic. Every time, you add points, you just overwrite the highest score with a current score
QUESTION
Good times. How do I implement the NPC rotation towards the selected object?
...ANSWER
Answered 2022-Jan-30 at 20:31Simply get the desired direction
QUESTION
i tried everything from creating a new project, downloading inputsystem from packagemanager, manually and ... i tried editing assembley.csharp and adding hintpath... i tried reinstalling and importing old assets which input system worked well...
[{ "resource": "/C:/Driver/GAME MAKING/Repos/Unity2D/Pong-2-001018/Assets/Scripts/PlayerController.cs", "owner": "csharp", "code": "CS0234", "severity": 8, "message": "The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) [Assembly-CSharp]", "source": "csharp", "startLineNumber": 6, "startColumn": 19, "endLineNumber": 6, "endColumn": 30 }]
this is the problem. i just cant fix it it kills me. i can go back to old input system but why it shouldnt work?
even i downloaded last version of .net, runtime and sdk.
...ANSWER
Answered 2022-Jan-08 at 20:34I found an answer here but I have to do this everytime I build or play.
I just add this :
QUESTION
Here is the Code:
...ANSWER
Answered 2021-Aug-15 at 16:14Physics
and Physics2D
are separate in Unity and don't interact with each other.
Physics2D.Raycast()
belongs to Physics2D and only responds to Physics2D (BoxCollider2D, CircleCollider2D, PolygonCollider2D, etc.)
Physics.Raycast()
belongs to Physics and only responds to Physics (BoxCollider, SphereCollider, MeshCollider, etc.)
You are using Physics.Raycast()
when you should be using Physics2D.Raycast()
.
This is how you would do it:
QUESTION
I am trying to learn how to Raycast in Unity2D.
Here is my code:
...ANSWER
Answered 2021-Aug-11 at 18:44When you use Input.mousePosition
you get a Vector2
which represents the position of the mouse relative to the camera. This means the X and Y you get are actually the X and Y of the position of the mouse on the screen.
These coordinates are not world coordinates.
For example if you were to draw a ray from transform.position
of a player standing at 0,0,0
to the mouse position of 500, 250
you would get a gigantic and seemingly randomly pointing ray.
To convert from where the mouse is on the screen(Screen Coordinates) to what it's pointing to in-game(World Coordinates) you can use Camera.ScreenToWorldPoint
.
For example
QUESTION
Unity2D How to make game object to face opposite from the position of another game object? I have a fish that is going always forward and randomly rotating to make semi random movement, and i want that in range of player(shark) the fish change direction opposite to shark and start moving faster(trying to escape). I have speed increase already but i doknt know how to make the opposite direction.
...ANSWER
Answered 2021-Jun-13 at 14:55Notice: at the part when I am saying to add/subtract 90 (you’ll know when you get there), try adding 90, if that doesn’t work, try subtracting 90 to get the right result.
To make it move fully the opposite direction, you should do a few things. First, I will tell you about Mathf.Atan2(float y, float x)
. Atan2 is arctangent. Arctangent takes a position, and finds the amount of rotations to rotate at that object, in radians. Then, you would want to multiply by Mathf.Rad2Deg
, or radians to degrees. It converts radians to degrees, which unity uses. Then, you would add some degrees to face the opposite direction.
Here is a way to make an object look away from the the mouse:
QUESTION
I'm new to coding and to Unity2D, so please bear with me.
I've created a Character Controller, which is called via EventTriggers set against UI button objects. The controller works fine (though is probably overkill), but below are the challenges around the jump function I'm having. Any help on this is really appreciated.
Thanks so much!
Challenges
- Player jumps in the right direction even from a standstill.
- Player can keep jumping even when in the air.
Here is the script:
...ANSWER
Answered 2021-Jun-06 at 02:15The problems are in the end of fixed update. This is what you have:
QUESTION
I'm making a Unity2D mobile game but I'm stuck on making a menu. I want the in-game menu and if the player touches the screen or clicks the screen, the game will start and the menu will be have store, options but I don't know how to do it. I tried to do the same scene but this time when it goes to the next level, the menu disappears. I searched on the internet but couldn't find it. Thanks.
...ANSWER
Answered 2021-Jun-03 at 17:05You should first create a UIManager script for yourself. In this script, you must define 2D elements such as Text, Canvas, Panel and provide their functionality. Then you can control these functions in your main manager (GameManager). To put it simply, it takes almost a video tutorial to explain it. Because this is not a simple code error question, man.
QUESTION
I have had problems with the OnDrop method, it is that it is not called, I was reading and maybe it has something to do with a Raycaster component, but I'm not sure, I don't even have knowledge of it, if someone could explain this to me I would greatly appreciate it.
Here is my code in c # plus an image of my hierarchy in Unity2D:
...ANSWER
Answered 2021-Apr-19 at 05:45OnDrop method is not called
To ensure the Method gets called you need to ensure that both the name and inherited class you use is correct.
As it seems you need to use override
for each function and instead of IDropHandler
and MonoBehaviour
inherit from EventTrigger
.
Example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Unity2D
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page