Rigidbody2D rb;
public float speed=2;
void Start()
{
rb= GetComponent();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector2(, ) ;
}
void OnCollisionEnter2D(Collision2D other)
{
Destroy(gameObject);
}
}
I dont know what to do with that Vector2
Velocity
on the Z-axis is not represented in Unity 2D because this axis is perpendicular to the game plane. To change the z-position of a 2D object, you must change the transform.position
directly. For example:
void Update()
{
transform.position += Vector3.forward * speed * Time.deltaTime;
}
_
Note: the object, when constantly moving along the Z axis in the 2D world, will sooner or later go beyond the camera’s visibility.