Comment on: Programmers are having a huge debate over whether they should be required to behave respectfully to each other
0 06 May 2018 18:34 u/FlamingoBumblebee in v/programmingComment on: Coding Saves
...then the IT guy walks in and...bau-chicka-bum-bau...she's workin'that copy machine like nobody's business
Comment on: Is there a good guide on the basic of Unity? I started using this today, and I think it's far less intuitive than it could be.
SpriteRenderer is a component. Canvas is an object. the Canvas object is called Canvas when you add it. SpriteRenderer has to be added to an object.
edit: just to clarify, the components use their type as their name as well. SpriteRenderer is called SpriteRenderer in the inspector. it will be attached to an object, though, so to create a reference to it you will first need to find the object and then GetComponent from that object.
Comment on: Is there a good guide on the basic of Unity? I started using this today, and I think it's far less intuitive than it could be.
the premade objects you add use their type as the name, so Canvas's type is Canvas. if you want to access a component on the canvas you would reference the canvas and then get the component using canvas.GetComponent.
as far as I can remember, the spaces will not be in the name of the type. I think it automatically removes them if you use them in the name of the script, but I can't be sure as I don't use them in the names of my scripts. I use PascalCase for my scripts and methods/functions, and camelCase for my variables.
Comment on: Is there a good guide on the basic of Unity? I started using this today, and I think it's far less intuitive than it could be.
the SpriteRenderer's type is SpriteRenderer so you would access it like:
private SpriteRenderer spriteRenderer;
and define it as:
spriteRenderer = GetComponent(typeof(SpriteRenderer)) as SpriteRenderer;
also anything that has a script on it has a type of NameOfScript.
if you want to access a script called VoatGoat you would access it like:
GetComponent(typeof(VoatGoat)) as VoatGoat;
use GetComponent when the script you want is on the same object as the script you're calling it from.
if you want the object the VoatGoat script is on you would do:
private GameObject voatGoat;
and define it as:
voatGoat = FindObjectOfType(VoatGoat)).gameObject as GameObject;
Comment on: Is there a good guide on the basic of Unity? I started using this today, and I think it's far less intuitive than it could be.
if you have a player script on an object (the player, presumably) and you want to access it from another script, you would declare a variable in the other script like:
c#:
private Player player;
and in Start() (or Awake(), or OnEnable(), or OnTriggerEnter(), or in another method/function, etc) you would add:
player = FindObjectOfType(typeof(Player)) as Player;
and then you would use the player variable to access that script.
those were just examples, but you shouldn't use FindObjectOfType in methods/functions directly. you should store a reference to the Player object, or whatever object, in Start() or Awake() and then store a reference to it in a variable in your method/function and call the necessary part of the script from there.
Comment on: Seven useful programming habits
ive done it a few times on voat by accident after typing a comment. then i politely tell my pc that i don't actually want a desktop link
Comment on: Seven useful programming habits
the "ctrl-s" made me chuckle. i, too, do it instinctively when i stop typing, lol
Comment on: I was mocking a coworkers so hard that I triggered it and it stubbed itself.
well played
Comment on: 10 sites that will teach you to code for free
lol, freeFoodCamp. who doesn't like typos?
Harassment is harmless as long as it's only the tip