using UnityEngine;
using System.Collections;
public class Sidewalls_Init : MonoBehaviour {
public Material SidewallMaterial;
void Update() {
SidewallMaterial.color = Color(255, 255, 255, 1);
}
}
Color is “errored”, saying, quotation: Assets/Scripts/Sidewalls/Sidewalls_Init.cs(7,34): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected.
Knowing my knowledge it should be #FFFFFF, 100% opacity.
You’ve got it right, but there’s a little JS in your syntax. Change Color to new Color and that should work. Also if you wanna get the material from a particular object that this script will go on, you can do something like…
Material m = gameObject.getComponent().material;
And then go on with your above code. It’s a great way to have strobe-like tints on your textures
Sure. A few things… First, change Update to Start. This operation doesn’t appear to be needed every frame of your game Second, you can get the material being used by your object with the code I listed above. And lastly, when you edit materials, it turns them into their own instance of that material. SidewallMaterial isn’t connect to your object, it’s just defined in the class on your object. They are the same material until you edit it.
No matter how you go about this, you’ll at some point need to access the mesh by getting it off your object. Here’s a few options for you:
/*option one - directly access and change the material*/
void Start()
{
gameObject.getComponent<MeshRenderer>().material.color = new Color(255,48,48,1);
}
/*option two - using a temporary variable*/
void Start()
{
Material m = gameObject.getComponent<MeshRenderer>().material;
m.color = new Color(255,48,48,1);
/*This might not be necessary, I forget.*/
gameObject.getComponent<MeshRenderer>().material = m;
}
/*option 3 - using your existing variable*/
void Start()
{
SidewallMaterial.color = new Color(255,48,48,1);
gameObject.getComponent<MeshRenderer>().material = SidewallMaterial;
}
I recommend any of them. Using a temporary variable might be the best for future cases where you don’t need a reference to the material often, but when you do you will have that temporary variable to do multiple things to.
Pssssst. Your code produces error, apparently “getComponent” in each case needs to be “GetComponent”.
I must have misplaced scripts or something like this. I see how these codes would work, normal logic, but they don’t on my. I apply this script on “Sidewall” element, the “Sidewall” has “Empty Material” in it and “Empty Material” is also in slot.
That should make the error clear, if there is one. You should see False, False and then color data. If you see True for either of the first two, your object’s mesh renderer is bugged lol.
Psssst… “MonoBehavior” has to be “MonoBehaviour” :).
False, false, RGBA(0.071, 0.071, 0.071, 1.000). I’ve put it in the same Sidewall object the previous script sat in, it produced this result, removing previous script, remained exact result. Switching “Owner” to “gameObject” or “GameObject” won’t work, produces some kind of error, used “this.name” instead, couldn’t put anything.
I was editing that script in notepad++, so it didn’t catch any of that xD
So if you disable every script on the object and run only 1 that modifies the material tint, it does nothing? Maybe you could provide screenshots or something.
“So if you disable every script on the object and run only 1 that modifies the material tint, it does nothing?”
The only script that we talked about in this topic, is the only script EVER attached to the object.
“Maybe you could provide screenshots or something.”
Heh, I started new conversation between us, I also sent link with entire project (it’s just couple files of my own), not really big, in fact, it’s quite basic. Because I don’t quite understand how screenshot would help? Script is attached to item, item doesn’t change color with in-the-face command :). You would see, exactly what I’m telling, heh, maybe video would be efficient but with my upload speed, it would be hardcore pain in the back.