UnityEngine.Rigidbody2D.AddForce C# (CSharp) Method

AddForce() public method

Apply a force to the rigidbody.

public AddForce ( Vector2 force, [ mode ) : void
force Vector2 Components of the force in the X and Y axes.
mode [ The method used to apply the specified force.
return void
        public void AddForce(Vector2 force, [DefaultValue("ForceMode2D.Force")] ForceMode2D mode)
        {
            INTERNAL_CALL_AddForce(this, ref force, mode);
        }

Usage Example

コード例 #1
0
ファイル: arroww2.cs プロジェクト: luliz/brazilball
    void Start()
    {
        myRB = GetComponent<Rigidbody2D>();
        myCL = GetComponent<Collider2D>();
        target = GameObject.FindWithTag("Player").transform;
        absDistance = Mathf.Abs(transform.position.x - target.position.x);
        Power = (1000 * absDistance) / 14;

        if (target.position.x > transform.position.x)
        {
            myRB.AddForce(new Vector2(Power, 0));
            transform.Rotate(new Vector3(0, 0, 270));
        }
        if (target.position.x == transform.position.x)
        {
            myRB.AddForce(new Vector2(0, 100));
            transform.Rotate(new Vector3(0, 0, 270));
        }

        if (target.position.x < transform.position.x)
        {
            myRB.AddForce(new Vector2(-Power, 0));
            transform.Rotate(new Vector3(0, 0, 270));
        }
        Destroy(gameObject, 3);
    }
All Usage Examples Of UnityEngine.Rigidbody2D::AddForce