Skip to content

Instantly share code, notes, and snippets.

@arket
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arket/524a187f48b7b57c8c6f to your computer and use it in GitHub Desktop.
Save arket/524a187f48b7b57c8c6f to your computer and use it in GitHub Desktop.
攻撃された座標を記憶
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // ジェネリックコレクション利用
class SaveList: MonoBehaviour {
List<Vector3> positionList = new List<Vector3>(); // リスト定義 (この場合はVector3型のリスト)
void OnCollisionEnter(Collision c) {
if(c.gameObject.tag == "EnemyBullet")
positionList.Add(this.transform.position); // リストへ追加
}
void Update() {
if(Input.GetKeyDown(KeyCode.E))
checkPosition();
if(Input.GetKeyDown(KeyCode.D))
delOldPosition();
}
void checkPosition() {
if(positionList.Count > 0){
// リストへアクセス
foreach(Vector3 v in positionList){
Debug.Log(v);
}
}
}
void delOldPosition() {
if(positionList.Count > 0)
positionList.RemoveAt(0); // リストから要素を削除
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment