当前位置:   article > 正文

添加2d刚体力_rigidbody2d.addforce

rigidbody2d.addforce
using UnityEngine;
using System.Collections;


public class force : MonoBehaviour {
public float x_power=0.0f;
public float y_power=0.0f;


// Use this for initialization

// Update is called once per frame
void FixedUpdate () {
if (Input.GetMouseButtonDown (0)) {
rigidbody2D.AddForce(new Vector2(x_power,y_power));
}

}
void OnCollisionEnter2D(Collision2D col)
{
UnityEngine.Debug.Log(col.gameObject);
if(col.rigidbody)
{
col.rigidbody.AddForce(new Vector2(0.0f,300.0f));
   }
}
}
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号