Last active
August 29, 2015 14:00
-
-
Save arket/524a187f48b7b57c8c6f to your computer and use it in GitHub Desktop.
攻撃された座標を記憶
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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