0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#オブジェクトの移動

Last updated at Posted at 2022-08-23

:star2:オブジェクトの移動・ジャンプ:star2:   

:bulb:成果:bulb:

translate メソッド ・座標の数値を更新していく ・166,207
// マウスのクリックで移動(座標の更新)
// ---------------------------------------------------------  
    float speed = 0;
    void Start()
    {
        Application.targetFrameRate = 60;    
    }
    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            this.speed = 0.2f;
        }        
        transform.Translate(this.speed,0,0);
    }
// ---------------------------------------------------------
AddForceメソッド Rigidbody2D コンポーネントのAddForceメソッドを利用する P267
    Rigidbody2D rigid2D;
    float moveForce = 20.0f;

    void Start()
    {
        Application.targetFrameRate = 60;    
        this.rigid2D = GetComponent<Rigidbody2D>();
    }
    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            this.rigid2D.AddForce(transform.right*this.moveForce);
        }        
    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?