Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Last active December 29, 2015 21:49
Show Gist options
  • Save Buravo46/7732148 to your computer and use it in GitHub Desktop.
Save Buravo46/7732148 to your computer and use it in GitHub Desktop.
【Unity】2D用の衝突判定スクリプト。
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]);
}
}
}
#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