view Assets/DeathZone.cs @ 8:599bd8ddb72b

Create Item Tree and Create Stage.
author Kazuma Takeda
date Tue, 17 Jan 2017 19:57:19 +0900
parents
children
line wrap: on
line source

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeathZone : MonoBehaviour {

	private GameObject target;
	private Vector3 firstPoint = new Vector3(0.5f, 2f, 0.5f);

	public delegate void HitCallback (int n);
	public HitCallback hitcallback;

	public void SetHitCallback (HitCallback hc) {
		this.hitcallback = hc;
	}

	private void Start () {
		target = GameObject.FindGameObjectWithTag ("Player");
	}

	private void Update () {
		Vector3 pos = target.transform.position;
		this.transform.position = new Vector3 (pos.x, this.transform.position.y, pos.z);
	}

	private void OnTriggerEnter (Collider col) {
		if (col.tag == "Player") {
			target.transform.position = firstPoint;
			if (hitcallback != null)
				hitcallback (1);
		}
	}
}