タッチした位置にオブジェクトを移動させる C#
ひとつ前の記事に書いたのですが、わりと需要ありそうなので別記事で一応立てておきました。
Tweenを使うとたったのこれだけで移動出来ちゃう。
今回2DなのでカメラはOrthographicにしておいてください
[SerializeField] GameObject a;
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) {
Vector3 aTapPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
iTween.MoveTo (a.gameObject,iTween.Hash("x",aTapPoint.x,"y",aTapPoint.y,"time",1.0f));
}
}
このaに動かしたいオブジェクトを突っ込むと、クリックした位置に1秒で移動するという動きを行います。
動き方に関してはeaseType一覧をこちらで確認下さい。