Last active
December 29, 2015 21:49
-
-
Save Buravo46/7732148 to your computer and use it in GitHub Desktop.
【Unity】2D用の衝突判定スクリプト。
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; | |
public class Collision2DScript : MonoBehaviour { | |
// 切り替え先のScene名を格納している配列 | |
public string[] sceneName; | |
// 衝突したオブジェクト名を格納している配列 | |
public string[] objectName; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
void OnCollisionEnter2D(Collision2D collision){ | |
// 衝突したオブジェクトのtagがBlockならば | |
if(collision.gameObject.tag == objectName[0]){ | |
// GameOver | |
Application.LoadLevel(sceneName[0]); | |
} else if(collision.gameObject.tag == objectName[1]){ // 衝突したオブジェクトのtagがGoalならば | |
// GameClear | |
Application.LoadLevel(sceneName[1]); | |
} | |
} | |
} |
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
#pragma strict | |
// 切り替え先のScene名を格納している配列 | |
var sceneName:String[]; | |
// 衝突したオブジェクト名を格納している配列 | |
var objectName:String[]; | |
function Start () { | |
} | |
function Update () { | |
} | |
function OnCollisionEnter2D(collision : Collision2D){ | |
// 衝突したオブジェクトの名前がBlockならば | |
if(collision.gameObject.name == objectName[0]){ | |
// GameOver | |
Application.LoadLevel(sceneName[0]); | |
} else if(collision.gameObject.name == objectName[1]){ // 衝突したオブジェクトの名前がGoalならば | |
// GameClear | |
Application.LoadLevel(sceneName[1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment