- Home /
C# EdgeCollider2D Points Not Updating Continuously
I'm trying to make a script that creates a GameObject with a Line Renderer, a Edge Collider2D and have the scripted gameobject attach to another gameobject called go. I was able to set the Line Renderer's positions. But when I try to set the Edge Collider2D's points it only updates once and not continuously as it should be in the Update function. Is there a different method of setting the Edge Collider2D's points that updates continuously?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LineConnect : MonoBehaviour {
public GameObject go;
private EdgeCollider2D col;
private LineRenderer line;
void Awake() {
col = GetComponent<EdgeCollider2D>();
line = GetComponent<LineRenderer>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 linePos = new Vector3 (transform.parent.position.x,transform.parent.position.y - 0.45f, transform.parent.position.z);
Vector2[] colPoints = new Vector2[]{new Vector2(0,0.5f),new Vector2(go.transform.position.x,go.transform.position.y)};
col.points = colPoints;
line.SetPosition(0, linePos);
line.SetPosition(1, go.transform.position);
}
}
I don't know the exact approach for this but there is one out of line (worst solution), Only try this if you don't get any other good solution.
Try to reset the collider after some time interval (like 1 or 1.5 seconds) by Removing and adding the collider.
I tried that, the Edge Collider2D's points still aren't updating continuously.
Try a Debug.Log to make sure everything is working the way it should.
Debug.Log just shows me what I already know. That Edge Collider2D's points the aren't updating continuously.
Debug.Log(col.points.ToString());