clothRender.renderer.material = this.renderer.material;
don’t work the line code.
this’s my code:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(InteractiveCloth))]
[RequireComponent(typeof(ClothRenderer))]
public class AttachInteractiveCloth : MonoBehaviour
{
public PrimitiveType defaultMesh;
public bool removeMehsRender = true;
public bool removeCollider = true;
void Awake()
{
bool useDefaultMesh = (this.GetComponent<MeshFilter>() == null);
GameObject useObject = useDefaultMesh ? GameObject.CreatePrimitive(defaultMesh) : this.gameObject;
InteractiveCloth thisCloth = this.GetComponent<InteractiveCloth>();
ClothRenderer clothRender = this.GetComponent<ClothRenderer>();
MeshFilter thisMeshFilter = useObject.GetComponent<MeshFilter>();
if (clothRender != null && this.renderer.material != null)
{
Debug.Log("cloth renderer");
clothRender.renderer.material = this.renderer.material;
}
if (thisCloth != null && thisMeshFilter != null)
{
thisCloth.mesh = thisMeshFilter.mesh;
if (removeMehsRender && this.GetComponent<MeshRenderer>())
{
Destroy(this.GetComponent<MeshRenderer>());
}
if (removeCollider && this.collider)
{
Destroy(this.collider);
}
}
if (useDefaultMesh)
{
Destroy(useObject);
}
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}