I am using the DistanceJoint 2d for a ninja rope effect.
how can I attach a graphic material to it? so it will look like a rope?
For the rope draw a line using Line Renderer with two points of line as 2 and connectedAnchor from the DistantJoint2D. You can set the material for this line renderer to the material you want.
Found it:
Create EmptObject and attach Effects->LineRenderer.
then Attach the Following Script to the new Object
using UnityEngine;
using System.Collections;
public class DrawLine : MonoBehaviour {
public GameObject[] targets; // the objects to draw the line between
// Use this for initialization
private LineRenderer l;
void Start () {
l =this.GetComponent<LineRenderer>();
Vector2 p1 = targets [0].transform.position;
l.SetPosition (0, p1);
}
// Update is called once per frame
void FixedUpdate () {
Vector2 p1 = targets [0].transform.position;
Vector2 p2 = targets [1].transform.position;
Vector2 lineVector = p2 - p1;
l.SetPosition (0, p1);
l.SetPosition (1, p2);
}
}