public float x_power = 0.0f;
public float y_power = 100.0f;
private Rigidbody2D rb2D;
void Start()
{
rb2D = gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
}
private void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 x_force = new Vector2(x_power, y_power);
rb2D.AddForce(x_force);
}
}
//检测是否碰撞
private void OnCollisionEnter2D(Collision2D collision)
{
UnityEngine.Debug.Log(collision.gameObject);
//是否存在刚体
if (collision.rigidbody)
{
collision.rigidbody.AddForce(new Vector2(0.0f, 200.0f));
}
}