As I tend to go on and over-explain things, here is the short point version =]
- I am writing a script =]
- From a Menu Item I am creating a gameObject
- To this gameObject I am adding : MeshFilter, “EllipsoidParticleEmitter”, ParticleAnimator, ParticleRenderer
- To the ParticleRenderer, I wish to assign the material Default-Particle
How do I find and then assign the material Default-Particle to the ParticleRenderer from a Menu Item, not runtime. Thanks.
Here is my current script :
@MenuItem("Custom/Particles/Mesh Emitter")
static function newParticleMesh()
{
var go : GameObject = new GameObject( "LegacyParticleMesh" );
go.transform.position = Vector3.zero;
go.AddComponent( MeshFilter );
go.AddComponent( "MeshParticleEmitter" ); // as ParticleEmitter;
go.AddComponent( ParticleAnimator );
go.AddComponent( ParticleRenderer );
//go.renderer.material.shader = Shader.Find("Particles/Alpha Blended Premultiply");
//go.renderer.sharedMaterial.shader = Shader.Find("Particles/Alpha Blended Premultiply");
}
Original Question :
How do I find and assign a native material and shader to a renderer? I am talking about the Default-Particle material that comes with Unity.
I am creating a custom menu item for legacy particle objects. Everything is fine except for when I want to apply Unitys native Default-Particle material.
when I use :
go.renderer.material.shader = Shader.Find("Particles/Alpha Blended Premultiply");
this is the error message :
Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead.
UnityEngine.Renderer:get_material()
CustomParticles:newParticleMesh() (at Assets/Editor/CustomParticles.js:27)
when I use :
go.renderer.sharedMaterial.shader = Shader.Find("Particles/Alpha Blended Premultiply");
this is the error message :
NullReferenceException
CustomParticles.newParticleMesh () (at Assets/Editor/CustomParticles.js:27)
I am trying to find and apply the Default-Particle texture with the default Alpha Blended Premultiply shader. How is the correct way to assign these to the particle renderer using script/code?
Like these ones =]
unity how to find and assign default particle material
here is the code :
#pragma strict
#if UNITY_EDITOR
// -- Custom / Particles --
@MenuItem("Custom/Particles/Ellipsoid Emitter")
static function newParticleEllipsoid()
{
var go : GameObject = new GameObject( "LegacyParticleEllipsoid" );
go.transform.position = Vector3.zero;
go.AddComponent( "EllipsoidParticleEmitter" );
go.AddComponent( ParticleAnimator );
go.AddComponent( ParticleRenderer );
}
@MenuItem("Custom/Particles/Mesh Emitter")
static function newParticleMesh()
{
var go : GameObject = new GameObject( "LegacyParticleMesh" );
go.transform.position = Vector3.zero;
go.AddComponent( MeshFilter );
go.AddComponent( "MeshParticleEmitter" );
go.AddComponent( ParticleAnimator );
go.AddComponent( ParticleRenderer );
go.renderer.sharedMaterial.shader = Shader.Find("Particles/Alpha Blended Premultiply");
}
#endif