當前位置: 首頁>>代碼示例>>C#>>正文


C# Rigidbody.AddForce方法代碼示例

本文整理匯總了C#中UnityEngine.Rigidbody.AddForce方法的典型用法代碼示例。如果您正苦於以下問題:C# Rigidbody.AddForce方法的具體用法?C# Rigidbody.AddForce怎麽用?C# Rigidbody.AddForce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.AddForce方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Start

    void Start()
    {
        bullet = this.GetComponent<Rigidbody>();
        bullet.AddForce(this.transform.forward *  thrust);

        GameObject.Destroy(this.gameObject, 3.0f);
    }
開發者ID:DarioDomiDE,項目名稱:SwitchWitch,代碼行數:7,代碼來源:BulletMovement.cs

示例2: applyLinearForce

 public void applyLinearForce(Rigidbody toBody, Vector3 desiredForce, bool relative)
 {
     if(relative)
         toBody.AddRelativeForce (desiredForce, this.forceMode);
     else
         toBody.AddForce (desiredForce, this.forceMode);
 }
開發者ID:rusticgames,項目名稱:rts,代碼行數:7,代碼來源:Mechanism.cs

示例3: Start

 // Use this for initialization
 void Start()
 {
     S = this;
     rb = GetComponent<Rigidbody>();
     rb.AddForce(Vector3.forward * 20);
     rb.AddForce(Vector3.up * 10);
     mouseXPos = 0;
 }
開發者ID:sspringg,項目名稱:Rapid_Game_Prototype,代碼行數:9,代碼來源:Monkey.cs

示例4: Start

 void Start()
 {
     rigidbody = GetComponent<Rigidbody>();
     if(Application.loadedLevel == 2)
     rigidbody.AddForce(800000000, 0, 0);
     else
     rigidbody.AddForce(71000, 0, 0);
 }
開發者ID:Extreme112,項目名稱:TomsCaveEscape,代碼行數:8,代碼來源:Giantboulder.cs

示例5: Start

    void Start()
    {
        sounds = GetComponents<AudioSource>();
        quack = sounds[0];

        rb = GetComponent<Rigidbody>();
        rb.AddForce(transform.forward * speed);
        rb.AddForce(transform.up * speed2);
    }
開發者ID:atb818,項目名稱:Duck-Game,代碼行數:9,代碼來源:bulletLogic.cs

示例6: Awake

    void Awake()
    {
        //reference to rigidbody and transform for force appplication
        rigidbody = GetComponent<Rigidbody>();
        orbital = this.transform;

        //starting force
        rigidbody.AddForce(Vector3.left * speed);
        rigidbody.AddForce(Vector3.up * speed);
    }
開發者ID:btrowbridge,項目名稱:Mesh_In_Unity,代碼行數:10,代碼來源:ParticleBehavior.cs

示例7: OnCollisionEnter

 void OnCollisionEnter(Collision col)
 {
     rb = GetComponent<Rigidbody>();
     if (col.gameObject.name.Contains("shield"))
     {
         rb.AddForce(col.gameObject.transform.forward * BounceStrength * -1);
     }
     else {
         rb.AddForce(col.gameObject.transform.forward * BounceStrength);
     }
 }
開發者ID:fbav,項目名稱:locomotion,代碼行數:11,代碼來源:Ricochet.cs

示例8: Start

    // Use this for initialization
    void Start()
    {
        //bullets set to disappear after thirty seconds, rotate for prefab weirdness
        initialForce = 300;
        Destroy(this.gameObject, 30);
        transform.Rotate(90,0,0);

        //initial force only
        body = GetComponent<Rigidbody>();
        body.constraints = RigidbodyConstraints.FreezeRotationY;
        body.AddForce(transform.right * Random.Range(-deviation,deviation));
        body.AddForce(transform.up * initialForce);
    }
開發者ID:jzhangx2,項目名稱:SpaceTown,代碼行數:14,代碼來源:bulletScript.cs

示例9: Start

    // Use this for initialization
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody>();

        int toss = Random.Range (1,3);
        switch(toss){
        case 1:
            myRigidbody.AddForce (-Vector3.right * 50, ForceMode.Impulse);
            break;
        case 2:
            myRigidbody.AddForce (Vector3.right * 50, ForceMode.Impulse);
            break;
        }
    }
開發者ID:Harley-Torrisi,項目名稱:Net-Hocky,代碼行數:15,代碼來源:Puck_Move.cs

示例10: jump

 public static void jump(Rigidbody player, Vector3 force)
 {
     if (GameManager.Instance.ThePlayer.GetComponent<PlayerProperties>().CheckGroundDist())
     {
         player.AddForce(force);
     }
 }
開發者ID:abiaco,項目名稱:ggj_2016,代碼行數:7,代碼來源:Action.cs

示例11: Start

    // Use this for initialization
    void Start()
    {
        if (directionRight)
        {
            direction = new Vector3(1.0f, 0.0f, 0.0f);
            offset = new Vector3(1.0f, 1.0f, 0.0f);
        }
        else
        {
            direction = new Vector3(-1.0f, 0.0f, 0.0f);
            offset = new Vector3(-2.0f, 1.0f, 0.0f);
        }

        if (!directionRight)
        {
            SpriteRenderer spriterenderer = gameObject.GetComponent<SpriteRenderer>();
            Vector3 scale = spriterenderer.transform.localScale;
            scale.x *= -1;
            spriterenderer.transform.localScale = scale;
        }

        gameObject.transform.position = player.gameObject.transform.position + offset;

        rigidBody = GetComponent<Rigidbody>();
        rigidBody.AddForce(direction * thrust, ForceMode.Impulse);
    }
開發者ID:c4tTi,項目名稱:GGJ16,代碼行數:27,代碼來源:FeuerwerkMovement.cs

示例12: Update

    // Update is called once per frame
    void Update()
    {
        hero = GetComponent<Rigidbody> ();
        anim.SetBool("is_jump", !grounded);

        if (grounded && ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)))) {
            hero.AddForce(new Vector3(0f, ForceJump, 0f));
            //soundJump.Play();
        }
        hero.velocity = new Vector3(move * MaxSpeed, hero.velocity.y, hero.velocity.z);

        if (move == 0) {
            anim.SetBool ("boolrun", false);
        }else
        {
            anim.SetBool("boolrun", true);
        }

        if (Input.GetKey (KeyCode.R)) {
            Application.LoadLevel(Application.loadedLevel);
        }

        if (facingRight && move < 0) {
            Flip();
        }
        else if(!facingRight && move > 0)
        {
            Flip();
        }
    }
開發者ID:YoGames,項目名稱:SumoWrestling,代碼行數:31,代碼來源:HeroController.cs

示例13: Start

 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody> ();
     rb.AddForce (transform.forward * speed);
     // 弾丸が作成された位置がFirePosの位置と同じ
     firePos = transform.position;
 }
開發者ID:kwbt-mrokj,項目名稱:S_Shooter01,代碼行數:8,代碼來源:BulletCtrl.cs

示例14: FixedUpdate

	// Update is called once per frame
    void FixedUpdate()
    {


        if (Input.GetKeyUp(KeyCode.Space))
        {
            if (!(jammersThrown == TotalJammers))
            {
                jammersThrown++;

                GameObject Clone = Instantiate(JammerGameObject);

                Clone.transform.position = JammerOrigin.position;

                jammerPhysics = Clone.GetComponent<Rigidbody>();



                jammerPhysics.useGravity = true;
                jammerPhysics.isKinematic = false;

                jammerPhysics.AddForce(transform.forward * 100);
            }
        }
    }
開發者ID:talhahasanzia,項目名稱:MazeBot-Old-Unity5.0,代碼行數:26,代碼來源:JammerThrow.cs

示例15: handleCollision

 public bool handleCollision(ControllerColliderHit hit, Rigidbody body, float force)
 {
     Vector3 pushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
     //		body.velocity = pushDir * force;
     body.AddForce (pushDir * force);
     return false;
 }
開發者ID:hannahjgb,項目名稱:AdventureGameFiles,代碼行數:7,代碼來源:PlayerPushHandler.cs


注:本文中的UnityEngine.Rigidbody.AddForce方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。