I'm trying to have it so that the player walks through a cloth curtain.
There's a sphere collider attached to my first person camera, and a cloth script attached to a prim plane. I'm trying to attach the FPS cam collider to the cloth object at runtime.
I wrote a script that seems like it should work, but it doesn't. No errors or nothing. The script compiles and works, but the sphere collider just doesn't connect to the cloth component. what gives?
public class ClothTest : MonoBehaviour {
private void Start() {
Cloth a = GetComponent<Cloth>();
var ClothColliders = new ClothSphereColliderPair[1];
ClothColliders[0] = new ClothSphereColliderPair(GameObject.Find("First Person Camera").GetComponent<SphereCollider>());
ClothColliders[0] = a.sphereColliders[0];
}
Here is a screenshot of the cloth component in the inspector:
You are trying to put the
SphereCollider
from your camera to yourCloth
butis doing the opposite. It is trying to put the
SphereCollider
from yourCloth
to the one in your camera. Change that around and also remove the[0]
from each side.That last line of code should be:
The complete new function: