---
# System prepended metadata

title: Unity 2D移動語法的不同
tags: [unity]

---

# Unity 2D移動語法的不同
###  Snake_direction =Vector2.up
會把Vector2設為(0, 1) 按下W,那就往上(unity預設的屬性)

``` C#= 
if(Input .GetKeyDown(KeyCode.W)){
            Snake_direction = (Vector2.up;)
            }
```

### this.gameObject.transform.Translate(new Vector2(X, Y) * Time.deltaTime );
直接改變gameobject位置,並透過*Time.deltaTime 讓移動速度與幀率之間維持平衡,不會因為幀率高低影醒物體移動,確保移動後的速度都一樣
``` C#= 
if(Input .GetKeyDown(KeyCode.W)){
this.gameObject.transform.Translate(new Vector2(X, Y) * Time.deltaTime );
            }
```

###### tags: `unity`
