Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

InteractiveCloth.AttachToCollider

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function AttachToCollider(collider: Collider, tearable: bool = false, twoWayInteraction: bool = false): void;
public void AttachToCollider(Collider collider, bool tearable = false, bool twoWayInteraction = false);
public def AttachToCollider(collider as Collider, tearable as bool = false, twoWayInteraction as bool = false) as void

Description

Attaches a collider to the cloth object.

Only has an effect if some vertices of the cloth are intersecting the collider. These vertices will then become static in their position with respect to the collider. If tearable is true, attachments can tear of, depending on the value of attachmentTearFactor. If twoWayInteraction is true, the cloth will apply forces back to the attached rigidbody, depending on the value of attachmentResponse.

See Also: DetachFromCollider function.

	// Attach this transform's collider to a cloth, make 
	// it tearable and two way interactive on forces.
	// REMEMBER: Only has an effect if some vertices of 
	// the cloth are intersecting the collider

var cloth : InteractiveCloth;

function Start() { if(cloth) cloth.AttachToCollider(transform.collider, true, true); else Debug.LogError("No cloth was assigned in the inspector"); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public InteractiveCloth cloth;
    void Start() {
        if (cloth)
            cloth.AttachToCollider(transform.collider, true, true);
        else
            Debug.LogError("No cloth was assigned in the inspector");
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public cloth as InteractiveCloth

	def Start() as void:
		if cloth:
			cloth.AttachToCollider(transform.collider, true, true)
		else:
			Debug.LogError('No cloth was assigned in the inspector')