How do you bend a cylindrical gameobject?

I’m trying to simply bend a cylinder in C#. The only way I can see to do this is to use mesh vertices.

	void Update () {
		Mesh cyl = GetComponent<MeshFilter> ().mesh;
		Vector3[] vertices = cyl.vertices;
		int i = 0;
		Debug.Log (vertices.Length);
		while(i < vertices.Length){
			vertices _+= Vector3.up * Time.deltaTime;_
  •  	i++;*
    
  •  }*
    
  •  cyl.vertices = vertices;*
    
  •  cyl.RecalculateBounds ();*
    
  • }*
    Obviously this code moves the cylinder up. I want to bend, but I’m not sure how to select certain vertices and then move them appropriately. Is it even possible to deform the cylinder with this method? If not how can it be done?

Is the ‘cly’ object Unity’s build-in cyclinder, or a cylinder you created? I don’t believe the built-in cylinder has any vertices on the sides…just top and bottom. You are going to need vertices at each bend point. You can author your tube in a 3D modeling program, or you could create one from script. The Tube object at the following link will give you a starting point, though you will need to expand it:

http://wiki.unity3d.com/index.php/ProceduralPrimitives