まずはSSで簡単なアニメーションを作りパーツに当たり判定をつけます。
unityに持っていった時に利用可能なのは
・なし
・四角形
・円形(スケール影響なし)
だけなのでご注意を今回は四角を選択します。
当たり判定のパーツの参照セルには半透明な画像など割り当てておくと
unity上で目視で確認が出来るので楽です。
作成したSSのデータをunityにインポート
方法は下記URLを参考に
gameobject-> 2dobject-> sprite 白い玉の2Dオブジェクトを追加
コイツをSSで作ったアニメーションに接触させます。
さらcolliderのComponentを追加
SSで作ったアニメーションのinspectorのisTriggerにチェックを入れる。
Viewにスクリプト(View.cs)を追加します。
内容は下記
using UnityEngine; using System.Collections; public class View : MonoBehaviour { GameObject Ball; GameObject anim; // Use this for initialization void Start() { Ball = GameObject.Find("Ball"); anim = GameObject.Find("anim"); anim.GetComponent<Script_SpriteStudio_Root>().FunctionColliderEnter = OnColliderEnter; } void OnColliderEnter(Script_SpriteStudio_Root InstanceRoot,string PartsName,int PartsID,Collider Self,Collider Pair) { //接触したパーツの名前をログに出す Debug.Log(PartsName); } // Update is called once per frame void Update() { //キー入力があったら白い玉を動かす Vector3 before = Ball.gameObject.transform.localPosition; int add = 10; if (Input.GetKey("a")) { before.x = before.x - add; } if (Input.GetKey("d")) { before.x = before.x + add; } if (Input.GetKey("w")) { before.y = before.y + add; } if (Input.GetKey("s")) { before.y = before.y - add; } Ball.gameObject.transform.localPosition = before; } } |
そして実行
青色の当たり判定に白玉が接触すると左にログが出てます。
おわり。
最近のコメント