Questions tagged [c#]

C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.

Filter by
Sorted by
Tagged with
0
votes
0answers
9 views

List<Vector3> of line segments (start, end position) from jointed CapsuleCollider chain

What I'm trying to do I'm trying to create a list of positions which I can use to define a centripetal catmull–rom spline; however I can't think of a solution for creating the list of positions which ...
0
votes
0answers
14 views

Script Functionality breaks when switching between scenes in the editor

For context, I've started making a 2D Unity game and am currently trying to implement a dialogue system. I only have two scenes in the game so far. Normally, the system works perfectly fine; pressing ...
1
vote
1answer
28 views

Sprite won't flip properly

I have a waypoint script I use to control enemy patrol movement in a given area. I use a reference to the Sprite Renderer to change the sprite facing direction. It starts with flipX set to false, by ...
0
votes
1answer
40 views

How to fix animation script so that humanoid character holds their weapon

I am trying to follow this tutorial video about setting up an third-person shooter character in Unity. But my character will not hold their weapon. I'm also getting the following warnings in my ...
1
vote
1answer
53 views

Help on calculating distance between player position and other object collider end

So, imagine the drawing in 3d and obstacle is in front of the player, and I do a raycast for checking in front of the player and if the raycast hits the obstacle the player needs to check both left ...
0
votes
1answer
25 views

Unity LoadScene did not seem to work properly

My logic is simple: after conditions are met, display an image (an Image class instance) and restart the stopwatch. After a certain time, reload the scene. In a <...
1
vote
0answers
16 views

Handling Multiple Collisions for 2d Platformer

I am looking for ideas on how to handle multiple collisions. For example: currently if my player character lands on an enemy tagged object, a raycast handles collision detection for a seamless kill. I ...
0
votes
1answer
49 views

How can I make an object follow behind the player with respect to its rotation such that the player never faces it and always remains behind them?

Below is a sample of my current code. It doesn't even move the object at all. I thought I could first get the current forward y rotation of the player and then flip it to get the backward rotation and ...
0
votes
1answer
18 views

Unity IAP - Collection was modified; enumeration operation may not execute

In Unity, after importing UnityIAP Version: 2.3.0, I have a button to which I attached an IAP Button component like in the image below: My SkinsPanel class looks like this: ...
0
votes
2answers
55 views

How to set a variable from the selected text of a dropdown menu in Unity?

I am trying to set a variable from the value of a DropDown menu in Unity. I wrote a script as follows, attached it to the dropdown and set it to run it in Unity under: On Value Changed (Int32). I have ...
2
votes
1answer
66 views

How to make mouse pointer be the vertex of a drawn parabola when estimating the trajectory of a projectile?

I'm trying to remake an old flash game using Unity. The main mechanic of the game is to make the basketball pass over the mouse. Here's a video of the game: https://www.youtube.com/watch?v=6sArMC1l_Sc ...
0
votes
1answer
40 views

Making vehicle using WheelColliders faster

I have a driving game and use wheel colliders to control cars, but whatever I change with the WheelCollider components it doesn't get faster and is way too slow. The code of the controller: ...
1
vote
2answers
78 views

Regarding performance, when is it okay and and when is it not okay to use LINQ with Unity?

As the title mentions I am interested in LINQ performance in Unity. When is it okay and when is it not okay to use it? As I understand it is bad to use it in something like ...
0
votes
0answers
27 views

How can I make the look at to be smoother slowly when using IK?

The script is very long so I will zoom in the specific script places of the problem and in the end I will add the full script too. The problem is at lines 209 - 235 when the player is smoothly looking ...
0
votes
1answer
43 views

Point System Using a GameManager?

I am trying to use a GameManager script to store and hold my players points, across multiple levels. The problem is that I have no idea how I should implement this. Should I declare the points ...
2
votes
2answers
83 views

Finding nearby tile objects with a certain tag more easily

I have generated a grid with hex tiles. I am using two different types of tiles and would like to at some points ask the tiles, how many tiles of each type they have as neighbours (or really, it would ...
0
votes
1answer
31 views

I'm trying to get forward, relative to mouse position

its a 3d game, where you start as a ball and collect a few things to get a win message.my first time ever coding something. heres my camera control code ...
0
votes
1answer
20 views

Unity UI Image not rendered?

In Unity I created a Panel with 3 children (An UI Image (LogoAch), and 2 TextMeshPro components (Name, Progress)). It looks something like down below: I saved this as a prefab and I try to instantiate ...
1
vote
1answer
62 views

Why the distance is never less than 1?

The distance is 1.07 and changing sometimes at this point the distance is 1.06 or 1.07 more or less this range. ...
0
votes
2answers
61 views

Help with multiple powerup types

I am trying to have a single class that handles multiple powerups types and using enum for the types of power-ups and switching the powers based on enum however when there are multiple power-ups in ...
0
votes
1answer
31 views

Change Sprite's Position

I have a sprite attached to the player like an accessory and it flips along with the player when moving in the opposite direction. However, due to the player being a dog, when flipped, the accessory ...
0
votes
0answers
36 views

How to lock an image once dragged & dropped in the correct position?

This drag and drop function in the code below works absolutely fine. Here when the correct image is dropped on to its correct place it stays, but how can I lock the image once it's dropped in its ...
0
votes
0answers
43 views

Reset rotation does not work properly

I have a unit, that targets enemies by turning it's upper body at them using LookAt. Whenever the unit dies, it plays two animations (one for the lower body and one for the upper body), which in most ...
0
votes
0answers
25 views

How to make the player run/walk and jump ? Blend the Jump with the Run/Walk

Now when I press the J key to jump the player stand still and jump on place. but I want to make that if I press W forward while the player is moving forward and than I press on J too the player will ...
0
votes
2answers
55 views

Destroy gameobject that is returning a RaycastHit2D?

As the title suggests I would like to destroy the game object that my raycast hits. I have a movement script attached to my player object. A raycast2d is continuously shot downward, and when it ...
-1
votes
0answers
15 views

How can I add a jump effect to the character move script?

I want to use the jump flag to allow or not allow the player to be able to jump. I tried this : but when I press the J key nothing happens. I added this public variable : ...
0
votes
0answers
6 views

Can a BoxCollider 2D be a child object of a Rigidbody 2D ? (as it's not working)

I tried to find a solution before and asked elsewhere but couldn't find the exact same issue. I have a parent game object that is a Rigidbody 2D, and this object has children that are BoxColliders 2D. ...
1
vote
2answers
42 views

Limit rotation/direction of two axes with seperate values (Vector3)

Issue I'm trying to create a vector pointing in a direction towards a target, and then using that vector rotate a child transform to face the target while limiting the rotation on the X and Y axis, ...
0
votes
1answer
28 views

Create buttons in the editor - Unity3D

So I've seen people do stuff like ...
0
votes
0answers
11 views

Accessing Canvas of instantiated prefab

I'm trying to instantiate a prefab that has a canvas and then access that canvas to enable it on or off. The prefab is for an inventory UI (has sprites, slots, etc., if necessary I can post some code, ...
0
votes
0answers
30 views

Integrating gpt2 into unity

I was wondering if anyone had any pointers in integrating gpt-2 into unity. I've got quite a bit of experience with python, but less with unity. What I'm trying to do is use a pretrained gpt2 model in ...
0
votes
1answer
43 views

How can I save a scene which consists of continuing text?

I am trying to make a simple book reading app. In scene, it will show only one word from the book every 0.5 seconds. What I want is, when I click pause then quit the game or just back to Main Menu and ...
1
vote
0answers
42 views

Forward movement while rotating lead to flickering

I'm trying to make a ship move forward while also turning, but when I start to play, the ship flickers when it tries to move and turn at the same time. (as comments suggested, I added other code for ...
1
vote
1answer
64 views

Character bounces when platform goes up and down

I have a player character with a few 2D Colliders and a Rigidbody 2D attached to it. When sitting on a platform the player ...
1
vote
1answer
31 views

Vector Rotation - Casting a Cone

I'm working on an obstacle avoidance system in unity, and my thought is to cast a sphere along the velocity; if it hits, draw a ring of spheres around that one and repeat until max ring count or a ...
-1
votes
0answers
19 views

Object reference not set to an instance of an object when scene restart [duplicate]

i made an object that add to int value on collision (playermoney script on empty obj on dontdestroyonload) but if scene restart (it restarts on collision with obstacle) on collision with object that ...
0
votes
0answers
32 views

Generating code on file changes in Unity Editor

I'm trying to generate code on changes using file watchers: ...
-1
votes
1answer
27 views

Error CS0234 and CS0236 in Unity

I'm trying to make a simple button perform an action when pressed. Initially I was using vscode, but as I couldn't solve the problem, I switched to visual studio 2017. For some reason the error ...
0
votes
0answers
27 views

How to check if object is inside another

Im creating a city building game, and i need to check if the building is 100% inside the grid, which is currently a 3d cube (using only the X and Z coordinates of the building) i thought to take the ...
1
vote
1answer
73 views

How to make my Unity project deterministic for replays?

I am working on an arcade-style 2D shmup and recently started implementing a replay system that allows players to view their runs of the game. I use the technique of recording input each ...
0
votes
0answers
18 views

How to get a reference of a script from prefab child?

The Scene Fader prefab is dragged to the OnGameLoading script : The scene fader prefab structure is with two children and the script I need to get a reference to is on the second child : And the ...
-1
votes
1answer
35 views

How can I detect when the mouse cursor is over a button?

Not clicked event but over the button event ? I want that when the mouse cursor is on the button call a function. When I click on the button it's calling the function playing a sound. I tried to add ...
0
votes
1answer
62 views

How to tile a texture

I'm creating a simple program in C# and now i'm trying to slice an image into multiple tiles similar to a grid pattern so it does not get stretched when drawing to different resolutions. What i'm ...
0
votes
0answers
18 views

Making texture atlas in Unity

For optimization purposes and reducing batches count, I am trying to combine my floor tiles textures into different atlases. Sharing the same material with an atlas can decrease draw calls and hence ...
0
votes
0answers
16 views

unity - playing animation in heavy load and in parallel

I'm basically having a large amount of code for UI, and it seems to be making my animation freezeup for a bit. I can't write paste the whole code here, but, here's an explanation of what's going on: <...
0
votes
0answers
79 views

How to implement texture slicing

I'm making a simple game in C# and i'm trying to slice my UI images into 9 smaller rectangles, so the image doesn't get stretched when drawing to different resolutions, but i'm having lots of problems ...
0
votes
1answer
53 views

VS code sometimes doesn't recognize Unity APIs

Unity debugger plugin and C# plugin are installed but Visual Studio Code does not recognize Unity APIs. Intelisense does not work. How can I fix?
0
votes
1answer
51 views
2
votes
0answers
42 views

How to move game pieces in checkers?

I have been creating a 3D Checkers board game via Unity. So far, I have managed to create the board game, with its game pieces well positioned into their designated rows and tiles upon starting to ...

1
2 3 4 5
153