I apologize before if this isn’t in the right section because I am new to unity and coding in C# MonoDevelop.
In my tutorials we are learning to change color by this piece of code:
this.renderer.materials.color
Now when I do this the “renderer” has a strikethrough and I cant access materials or color. I understand from someone else that .renderer can no longer be used like that? How do I go about changing a 3d object’s material color without the above? please try to explain it to a 2 year old because I just started C# 3-4 weeks ago. Thanks for the help in advance!
Also, why wont this activate the game object?
(ignore the space issues because it was copy and pasted)
using UnityEngine;
using System.Collections;
publicclassLightTrigger:MonoBehaviour{
publicGameObjectlightBulb=null;
voidOnTiggerEnter(Colliderother){
if(other.name==“Player”){
lightBulb.SetActive(true);
}
}
}
[ATTACH=full]187504[/ATTACH[/ATTACH]
there were some changes a while ago which removed the “quick accessors” like “renderer” (note lowercase r to start).
You need to explicitly use GetComponent() to access them now.
You can still use “gameObject”, “transform” and a few others here and there, but for the most part you should be using the GetComponent function. You can always cache the reference such as
Renderer rend;
void Start()
{
rend = GetComponent<Renderer>();
}
void Update()
{
rend.material.color = Color.red; // just an example, setting the colour every frame isn't exactly "useful" :)
}
2 Likes
Also - if you’re using Windows go download Visual Studio. MonoDevelop is garbage
Why exactly? I’m using monodevelop, and I think it works just as I expect it to
BTW:
Please, refer to the actual question in the title of a thread, and use [PLAIN]``[/PLAIN] tags for better readability
I see reports of instability and issues with really rudimentary functionality like copy-paste and indentation. Coupled with the fact that now the Unity tools for VS come bundled with the Unity install I really see no reason to not use it. I used MonoDevelop when I first started with the engine, switched to VS a few months in and the experience is just so much nicer and more robust.
It may be a pain in the arse at times but the integrated debugger is convenient, along with the automatic member listing.
Is there any way to debug a unity app through Visual studio or get automatic member listing to work in it?
Do the integrated tools for VS include runtime debugging?
Intellisense works just fine as does runtime debugging.
I’m using Monodevelop on windows and for some reason when i do this.renderer, renderer is crossed out. Why is this?
This is an old thread. In the future, please post a new thread if you have an issue or search for the answer if you can
As for your issue, that property is no longer valid. To get a reference to the renderer, use GetComponent. Example:
Renderer r = GetComponent<Renderer>();
or…
// if you're not keeping the reference.
GetComponent<Renderer>().someProperty = someValue;