unity普通力和位置力
/**
*
* Force-Practice
*
* */
using UnityEngine;
using System.Collections;
using UnityEngine.UI;//引用ui
public class Force_btn : MonoBehaviour {
public GameObject addNforce; //施加普通力的对象
public GameObject addPforce; //施加位置力的对象
public GameObject addPforceA; //位置力的目标
/// <summary>
/// 点击“普通力”函数执行
/// </summary>
public void Nforce()
{
addNforce.AddComponent<Rigidbody>().AddForce(100, 0, 0);
}
/// <summary>
/// 点击“位置力”函数执行
/// </summary>
public void Pforce()
{
Vector3 force1 = addPforceA.transform.position - addPforce.transform.position;
addPforce.AddComponent<Rigidbody>().AddForceAtPosition(force1, addPforce.transform.position, ForceMode.Impulse);
}
}