Question by
Luez_ · Jul 19, 2020 at 07:39 PM ·
transformdestroynot working
Why wont the target be destroyed?
Hey,
not very good at coding and i dont get why it wont destroy the target inside the scene.
public Transform target;
private void Update() {
RotateTowards(target.position);
}
private void RotateTowards(Vector2 target)
{
var offset = 140f;
Vector2 direction = target - (Vector2)transform.position;
direction.Normalize();
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(Vector3.forward * (angle + offset));
}
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.tag == "Player"){
Destroy(target);
}
}
Comment