C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

learn more… | top users | synonyms

1
vote
0answers
23 views

Unity play sound from Audio Source

I'm using the following code to play a sound in Unity 5: AudioSource aud = GetComponent("doorSound") as AudioSource; aud.PlayOneShot(aud.clip, 1.0f); But no sound is playing at all. What am I doing ...
1
vote
1answer
27 views

How to use Resources.Load with an AudioClip in Unity?

I'm trying to load an audio clip that's in my assets directory and play it. Here is my C# script: if (Input.GetKeyDown(KeyCode.X)) { audioSource = gameObject.GetComponent<AudioSource>(); ...
0
votes
2answers
52 views

MonoGame Gamepad Y axis flipped?

I'm following a book I bought on Google Play that is teaching me the ropes of MonoGame, and in Chapter 2 it introduces creating an input wrapper that takes care of all the input methods for a game pad ...
0
votes
2answers
30 views

How to use prefab only when in inventory game object?

I created an empty game object named "inventory", whenever I click on an object it transfers into that game object : and I got this far with the script: //Transforms public Transform Knife; //will ...
0
votes
1answer
38 views

Unity 2D C# Enemy Attackng Ai issue

Ok to be specific, both of my enemies will continuously play their attack animation even when it is false. I don't understand what I am doing wrong here :( void OnTriggerEnter2D(Collider2D other){ ...
0
votes
0answers
10 views

Unity Make a 3d object intersect pass through 2d UI

I'm trying to make a 3d object appear as if its approaching a 2d object. As So: The sprite is 3d and it should pass through the 2d button. Since the hand above can move freely I can't put it on a ...
1
vote
1answer
38 views

Check rotation before rotating

I am making a puzzle game in Unity. I have several GameObjects that have children objects where each child object has a BoxCollider2D. The game requires that the pieces be rotated, but to position ...
0
votes
2answers
35 views

Unity Non-shader method of combining two RGB Textures into a single RGBA Texture

I work in a broadcast environment that delivers video signals over SDI as Fill (RGB) and Key (A) signals. My SDI rendering method produces a Texture for each SDI input and applies it to a material. I'...
3
votes
3answers
84 views

Does AddForce continue to add force indefinitely?

Does the AddForce method continue add velocity to an object forever? Does it need to be limited by another line of code? Sorry if it is too broad or too simple; I am completely new to programming and ...
0
votes
1answer
21 views

Disabling object OnCollisionEnter and Enabling it On Collision exit

I have two objects that when they collide disable another gameobject. The problem is that I only want to have the other game object disabled while the two objects are touching and that I want to have ...
2
votes
1answer
111 views

How to add constant force to player with sperical gravity planet.?

I have a planet and character. My player move perfect around planet with pressing key like 'w','s','a and 'D'. I want to move my player on every frame with same force around sphere. I try plane ...
0
votes
0answers
19 views

Unity - Renderer.Bounds equivalent for GameObject without Renderer

I use a modified version of the 'Poor Man's Nested Prefab' script, it renders prefabs without using meshrenderer. Unity recognises it as an empty gameobject, so default focus distance (when I press f ...
-1
votes
0answers
23 views

How to move player with animation around shpere.?

I have a script modified by me. In my script i can not move my character with rigidbody.AddForce, Why i don't know but just play only animation not moving to forward. So I use rigidbody.velocity but ...
0
votes
1answer
71 views

Adding network support

I am trying to implement a simple game "Bulls and cows" in c#. It is a final project of my university course about design patterns. The target of the game is simple - try to guess the opponent number. ...
7
votes
2answers
90 views

Conditional Variables in Scriptable Objects

While using ScriptableObjects, how can I make some variables conditional? Example Code: [System.Serializable] public class Test : ScriptableObject { public bool testbool; public string ...
-4
votes
1answer
55 views

Unity c# - NullReferenceException: Object reference not set to an instance of an object [closed]

This is driving me crazy. I am new to C# and I always get this error when playing while it seems like a very simple code. I get the error at this line NullReferenceException: Object reference not set ...
0
votes
1answer
27 views

Can't add inspector variables to script?

So I just added this script to my project : https://www.assetstore.unity3d.com/en/#!/content/11278 Since this script only draws the lines on gizmos, I wanted to add a LineRenderer, so that I can draw ...
1
vote
0answers
125 views

In game replay system doesn't work correctly when animations are used on a character

I have created an in game replay system that essentially just stores each object's position and rotation at each FixedUpdate(). Once an even is triggered, the replay is then played back using ...
1
vote
0answers
51 views

How should I structure a Shared Library for different platforms for my MonoGame project?

I am quite new to the MonoGame/XNA framework and i have some structuring questions right now. One of the reasons I use MonoGame is because there is still that feeling to create a game from scratch ...
1
vote
1answer
35 views

Damping the Camera “lookAt” rotation

I have created a very short piece of code to make the camera look at a transform object. I locked the rotation of the x and z axis as it is only supposed to rotate on the y axis. I would like to add ...
0
votes
1answer
25 views

AutoFill function and methods not working in unity 5.3.5

I opened one of c# code in my projects, and edited something in the code, and I noticed that MonoDevelop no longer gives auto filling of function and method options. Below is the screen shot of the ...
0
votes
1answer
57 views

Monogame - custom json content importer

I am trying to build a JSON tile map importer for the content pipeline of Monogame but I'm having difficulty doing so. I have been following this tutorial and got something... But now it appears my ...
0
votes
0answers
19 views

How to use touch.deltaPosition properly?

I use following code for measure touch delata position: private Touch firstDetectedTouch; public Vector3 dragDistance; void Update() { if (Input.touchCount > 0) { ...
0
votes
0answers
9 views

How do I add EventTriggers to Multiple instantiated prefabs from a list?

I have a prefab which I am spawning a dynamic amount of. I want to attach an event trigger to each one of them, on pointerclick, to call a method accepting an int as parameter. I have the following ...
-1
votes
0answers
18 views

object is not smoothly moving using lerp and onMouseDrag

This is the code to move my object using lerp and mouseDrag event but it is not working very smoothly. //Camera Point smooth movment if (mouseWorking) { if ...
0
votes
0answers
28 views

Unity 2d variable has not been assigned when trying to instantiate

So I have some code here: using UnityEngine; using System.Collections; public class boardManager : MonoBehaviour { public GameObject GrassTile; void Start() { for (int i = 0; i <...
0
votes
1answer
74 views

How to keep a rigidbody on the ground going up/down a slope? (Unity 2D)

I'm not sure if this is possible, but Im working a 2D project to has randomly generated loops (imagine a sin or cos graph). I have a 2D character (a quad for now). I want my character want to ski a ...
0
votes
1answer
113 views

Slow collision detection at low frame rates

I'm experiencing an odd issue with my collision detection. I'm using the Update method to move the player (I don't want to use FixedUpdate because that creates an undesired weird movement). The fixed ...
0
votes
1answer
34 views

How can I use web browser controls for non-browser game GUI?

I'm looking for a way to get a modern browser's level of customization and rendering quality in my c# monogame to avoid using roundabout/limited/buggy GUI toolkits and to get better fonts without ...
-1
votes
0answers
29 views

Car animation bypass another Car animation

I have several animated car objects which have their own animation and animation control script. The car object is racing on the road and I want to manage all the car animation i.e., if any car is ...
0
votes
1answer
19 views

Mesh Chunk Combining and Extruding

So I'm working on a proceduraly generated level, that is composed of multiple chunks, so you don't go over the maximum amount of verts allowed in Unity Meshes. Another function is the ability to ...
0
votes
0answers
36 views

Monogame - tile map with XML instead of JSON

I'm working on the levels for my game so I've built these classes to read my maps: Tiles.cs: protected Texture2D texture; private Rectangle rectangle; public Rectangle Rectangle { get { ...
0
votes
1answer
42 views

How can i show all edges in monogame?

I am using Monogame 3.5 and i have simple model of cube. I use BasicEffect to draw it. I want it transparent so i use effect.Alpha = 0.5f. Is it possible to show all edges something like on picture?
-1
votes
2answers
84 views

Why doesn't Unity keep keydown states between scenes, and how can I change that?

So basically, when my scene in Unity changes and I'm holding down, say, Right or Left, when the scene resets, my player (and Unity) doesn't even recognize that I'm still holding that button, until I ...
17
votes
2answers
3k views

Player jittering against wall when held down button

So, I'm making a top down RPG. Everything's going excellent, but this problem is quite annoying. Now, when the character moves against the wall, the player jitters back and forth. I'm guessing it's ...
0
votes
2answers
46 views

How can I change my script execution order programmatically?

I have a script that I want to run before any other script. I want to change its execution order settings. I could do that using the Script Execution Order Settings option from within Unity, but I ...
0
votes
1answer
37 views

How to set only one collider with OnCollisionEnter(Collision col) in Unity?

I tried with this: void OnCollisionEnter(Collision col) { Debug.Log("hit everything"); if (col.gameObject.layer != LayerMask.NameToLayer("bico")) { if (col.gameObject.tag == "...
-1
votes
1answer
64 views

Increment int in array - int i is out of scope? [closed]

This is my scenario: I have a 3D model of a house, and an autonomously moving robot moving through the house picking up multiple objects. I have an array of 3 objects I want it to pick up, but I don'...
0
votes
2answers
54 views

What Collider should I use for my Player object?

I am making a 3rd person game with a simple orbit cam and it works fine most of the time, but since I have a box collider and I walk across an uneven surface, the player tends to tip over. How should ...
0
votes
1answer
32 views

Moving autonomous robot form one location to another based on array

I have a 3D model of a house, and I want an autonomous robot to move from 1 object in this house to the next one. I have it moving to the first, but it won't move to the second one. This is my code: ...
0
votes
2answers
32 views

Is There a Way To Keep Precision When Transforming GameObjects

I've seen this issue before, but it's never been a particular issue for me until today. I have each "room" of a dungeon created with a class script that contains details of that room. During the ...
0
votes
2answers
36 views

Autonomous robot - moving from 1 object to the next object

This question falls in line with my last question: Unity 3D - create autonomous moving robot in house + first person camera movement What I have I have a 3D model of a house; a first-person camera ...
0
votes
1answer
10 views

Drag event inverts in landscape mode

I am developing an car game for android with an UI steering wheel to control the car. I'm following Answer example for the wheel rotation. This is the code to rotate the wheel. rectT....
0
votes
0answers
38 views

How to make an object move in winform application c#?

I'm trying to make an object in such a way as to allow it to move. This is the objects that I initialized. This is a 25 cell board, made with 4 types. Black box is made from number 0, White box is ...
0
votes
1answer
41 views

Type `UnityEngine.UI.Text' does not contain a definition for `Text' [closed]

I came from Unreal Engine 4. I created a script, and I keep getting an error: Assets/scripts/UpgradeManager.cs(17,18): error CS1061: Type `UnityEngine.UI.Text' does not contain a definition for `...
0
votes
0answers
14 views

Resolution-Independent Rendering squishes view field

For the last couple of days, I've been trying to get a resolution-independent renderer going on an XNA game. I have a camera and a renderer class that I added, based on this tutorial Here's the ...
0
votes
0answers
18 views

Unity 5 New Netorking, SyncVars, RPC how does it actually work

I have just started working on a client - server flow for an open world game, as far as I understand unity have implemented a fairly new ways to communicate and work with networking but I cant seem to ...
0
votes
2answers
32 views

Lerp velocity in specific time

How to lerp velocity to 0 in specific time? For example in two seconds? I need this for jumping. velocity.Y = MathHelper.Lerp(velocity.Y, 0, [time]);