сделал мортиру работающую только при определенных значениях по y, как можно улучшить код что бы он работал при других значениях y и прилетал в цель?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
Rigidbody2D body;
float distance;
public Transform targetCube;
void Start()
{
body = GetComponent<Rigidbody2D>();
distance = (targetCube.transform.position.x - gameObject.transform.position.x);
body.AddForce(new Vector3(distance/2, 10, 0), ForceMode2D.Impulse);
}
}
Источник: Stack Overflow на русском