view 2D_Action_Game/Assets/Scripts/Enemy.cs @ 2:fdab88fc2cb9

add game projects
author Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:14:45 +0900
parents
children
line wrap: on
line source

using UnityEngine;
using System.Collections;

//敵
public class Enemy : Token {
	public static int Count = 0;

	// Use this for initialization
	void Start () {
		Count++;
//		サイズの設定
		SetSize (SpriteWidth / 3, SpriteHeight / 3);
//		ランダムに方向を移動する
//		方向をランダムに決める
		float dir = Random.Range (0, 359);
//		速さは2
		float spd = 2;
		SetVelocity (dir, spd);
	
	}
	
	// Update is called once per frame
	void Update () {
//		カメラの左下座標を取得
		Vector2 min = GetWorldMin ();
//		カメラの右上座標を取得
		Vector2 max = GetWorldMax ();

		if (X < min.x || max.x < X) {
//			画面外に出たので、X移動量を反映する
			VX *= -1;
//			画面内に移動する
			ClampScreen ();
		}
		if (Y < min.y || max.y < Y) {
//			画面外に出たので、Y移動量を反映する
			VY *= -1;
//			画面内に移動する
			ClampScreen ();
		}
	}

//	クリックされた
	public void OnMouseDown (){

//		GetComponent<AudioSource>().Play ();
		Count--;

		for (int i = 0; i < 32; i++) {
			Particle.Add (X, Y);
		}
//		破棄する
		DestroyObj ();
	}
}