x


Renderer.material not cloning?

I have a prefab which I would like to fade out the alpha on without fading out the alpha on all objects with that material. In the documentation it says the material should be cloned once changed but it's doesn't seem to do that in my project. I'm developing for Android, should that make any difference?

if (a > 0.0)
{
    a = a - 1.0/30.0;
    object.renderer.material.color.a = a;
}
else
{
    Destroy(gameObject);
}
more ▼

asked Oct 04 '11 at 06:02 PM

Breakmachine gravatar image

Breakmachine
55 5 8 10

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

renderer.material will instance a material and break any possible batching while renderer.sharedMaterial will not.

for your specific case, either it is a material instance and you haven't realized it (check the material on the object during gameplay for the Instance text next to the material name in the Inspector) or your script is not getting inside the "if" statement and thus not creating a material instance.

more ▼

answered Oct 05 '11 at 06:15 AM

loopyllama gravatar image

loopyllama
1.5k 1 4 18

(comments are locked)
10|3000 characters needed characters left

I found the problem. Both of my objects acted as if clicked because I was using an examplescript that wasn't specific to one object. ()

Have you got any good example of how to track if an item is "touched". I tried using RaycastHit but the variables "collider" and "rigidbody" is empty in the debugger.,My script is definitely entering the if statement, because it fades out all instances of the prefab. I'm not calling renderer.sharedMaterial, I'm calling renderer.material.

After clicking one of my objects both get (Instance) after the material name.

Now I'm starting to think that both objects pick up the click (touch).

more ▼

answered Oct 05 '11 at 08:05 AM

Breakmachine gravatar image

Breakmachine
55 5 8 10

(comments are locked)
10|3000 characters needed characters left

My bad. I was using an example that wasn't intended for this kind of function. So whenever a Raycast hit an object all my prefabs acted as if clicked.

Have you got any examples of clicking/touching objects? I've tried using RaycastHit but the variable collider return null.

more ▼

answered Oct 05 '11 at 08:05 AM

Breakmachine gravatar image

Breakmachine
55 5 8 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x813
x507
x328
x275
x130

asked: Oct 04 '11 at 06:02 PM

Seen: 889 times

Last Updated: Oct 05 '11 at 08:05 AM