Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 75627

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

2 votes

How to access a variable from another C# script in Unity

You can't, it's private. Now, that's not the end of things, as I suspect that wasn't really your question. Firstly, you need a reference to this script. Which you can get from a reference to the game …
Draco18s no longer trusts SE's user avatar
2 votes
Accepted

Unity: Cannot access variable of C# script from another object

This is caused by Unity But it's easy to fix. The Standard Assets folder is compiled before all other scripts (this may be a holdover from when Unity officially supported JavaScript / UnityScript file …
Draco18s no longer trusts SE's user avatar
1 vote
Accepted

I have a switch cameras script and two cameras but the switching is not working good. How ca...

m_Camera is a cached reference; Camera.main is not When you change what camera is enabled, this changes the result of Camera.main (as Camera.main litterally does an uncached GameObject.FindWithTag("Ma …
Draco18s no longer trusts SE's user avatar
1 vote
Accepted

How can I change the speed mode in Update?

Don't do this: private void Update() { RandomSpeed(); } The only thing you should do during Update() regarding speeds is to check to see if the value of randomSpeed has changed, and if so, genera …
Draco18s no longer trusts SE's user avatar
1 vote

How do I instantiate a prefab to a specific coordinate?

The Unity Manual contains an example: public class ExampleClass : MonoBehaviour { public Transform prefab; void Start() { for (int i = 0; i < 10; i++) { Instantiate(prefab …
Draco18s no longer trusts SE's user avatar
0 votes

Nothing happens when I press play in Unity3D

It does not appear that you have any scripts attached to the main camera (or any other game object). Scripts need to be attached to a GameObject to run.* *There are exceptions to this, as with any r …
Draco18s no longer trusts SE's user avatar
2 votes

Unity 3D C# - Shifting beetween worlds?

This is kind of an extension to @jackmott's answer, similar his suggestions, but different. Instead of using GameObject.SetActive() to flip the states of everything in the scene, I would instead sugg …
Draco18s no longer trusts SE's user avatar
1 vote

How are methods like Awake, Start, and Update called in Unity?

They are internal event handler methods. The engine probably calls them via Invoke("Method") though I am not sure on the internal implementation. The important thing is that they are named exactly a …
Draco18s no longer trusts SE's user avatar
11 votes
Accepted

Why does Physics2D.Raycast automatically fail if applying a layer mask?

A Layer Mask is an integer, so that's right. But if you want to test against Layer 8, you don't pass in 8 as the value. What if you want to check against 8 and 7? Well, 15 is the wrong answer there …
Draco18s no longer trusts SE's user avatar
1 vote

Picking up items and references

it only works if there is a drop object already present when the script begins, but there shouldn't be a drop object then Well, that's because you find a drop(ped) object during Start() which is …
Draco18s no longer trusts SE's user avatar
1 vote
Accepted

Question about references

You see where you have this line: Instantiate(itemPrefab, transform.position - offset, Quaternion.identity); Instantiate returns an object, that being the object created. Know what you can do with …
Draco18s no longer trusts SE's user avatar
0 votes

rotate object 0 to 90 with speed 1 then wait then 90 to 0 degree with 1 speed unity c#

In RotateMe2 you have this line: var toAngle2 = Quaternion.Euler(transform.eulerAngles + byAngles2); The current transform.eulerAngles is (90,0,0). The byAngles2 (passed to the function from Start) …
Draco18s no longer trusts SE's user avatar
7 votes

Why when getting the waypoints objects in script the order in the array is not the same as i...

The scene hierarchy can be reordered by dragging things around. However the default ordering (the order in which the objects were created) still applies. The GameObject.FindGameObjectsWithTag() metho …
Draco18s no longer trusts SE's user avatar
1 vote
Accepted

Modifying z axis position of a canvas and adapting it to camera

((RectTransform)textcanvas.transform).anchoredPosition The problem here is a very basic one: Canvas objects aren't Transforms. Transform objects are the only ones that contain position information, s …
Draco18s no longer trusts SE's user avatar
1 vote

How can I rotate object on key press?

You need parts from both of your attempts: if (Input.GetKeyDown(KeyCode.R)) This will trigger exactly once until you let go of the key again. This is exactly the behavior you describe as wanting to …
Draco18s no longer trusts SE's user avatar

1
2 3 4 5
15 30 50 per page