Line drawn out of a gameobject does not collide with another gameobject
Hey,
I have 2 Gameobjects which are just primitive shapes and one gameobject, which only has a linerenderer as a component.
Now the script of gameobject A makes that I draw a line after clicking on the gameobject with the starting point being in this gameobject and the end point is the current position of the mouse.
What I want to achieve is, that when the end of the line (at the mouse) collides with the collider of gameobject B, the end point of the line is set to the position of the gameobject B.
So this is the code for gameobject A:
public class Draw_Connecting_Line : MonoBehaviour {
private LineRenderer lineRenderer = new LineRenderer ();
public Transform origin;
public Transform destin;
void Awake () {
lineRenderer = GameObject.Find ("Line").GetComponent<LineRenderer> ();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseDrag () {
lineRenderer.SetPosition (0, new Vector3 (origin.position.x + (GetComponent<SpriteRenderer>().bounds.size.x)/2, origin.position.y, origin.position.z));
lineRenderer.SetPosition (1, Camera.main.ScreenToWorldPoint(Input.mousePosition));
}
}
And this is the code for the gameobject with the Line Renderer:
public class LineScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision col) {
if (col.gameObject.CompareTag("inputB1")) {
Debug.Log ("COLLISION!!!1111");
Destroy (col.gameObject);
}
}
}
Both gameobject A and B have a circle collider 2D component and also a rigidbody 2D component with kinetic body types. When I start the game and draw the line to gameobject B, nothing is written in the console, like no collision is detected. Also the tag of gameobject B is indeed "inputB1".
What am I missing or doing wrong here?
Your answer
Follow this Question
Related Questions
C# - My increament code is not working? 1 Answer
Executing a function upon 2d collision 1 Answer
Collision between two 2D objects. 1 Answer
Prevent "useless" character movements 0 Answers
Collisions not working in top-down RPG? 0 Answers