Created
September 21, 2016 16:23
-
-
Save takoyakiroom/fec73c288a710bda5c65edc1a2d38ab1 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; | |
public class FireWall : MonoBehaviour { | |
public GameObject Effect; // 爆風エフェクト | |
int power; // 火力 | |
Vector3 scale; // サイズ | |
Vector3 pos; // 位置 | |
int counter = 0; // 爆風を長くする用のカウンタ | |
bool bStop = false; // 障害物に当たったか | |
GameObject particle; // パーティクル | |
public void Init(int pow) | |
{ | |
power = pow; | |
// 当たり判定 | |
scale = transform.localScale; | |
pos = transform.localPosition; | |
// パーティクル | |
particle = (GameObject)Instantiate(Effect, transform.position, transform.rotation); | |
// しばらくしたら消滅させる(適当に4秒くらいで) | |
Destroy(particle.gameObject, 4.0f); | |
} | |
void FixedUpdate () { | |
// 当たり判定拡大 | |
if (counter < power * 15) | |
{ | |
// 壁にあたった? | |
if (bStop == false) | |
{ | |
// 当たっていないなら、当たり判定拡大 | |
transform.position += transform.forward * 0.1f; | |
scale.z += 0.2f; | |
transform.localScale = scale; | |
// パーティクルの位置を移動 | |
particle.transform.position += particle.transform.forward * 0.2f; | |
} | |
} | |
else | |
{ | |
// パーティクル止める | |
foreach (Transform trans in particle.transform) | |
{ | |
ParticleSystem part = trans.transform.GetComponent<ParticleSystem>(); | |
part.loop = false; // ループ止め | |
} | |
// 消える | |
Destroy(this.gameObject); | |
Debug.Log("FireWall Destroy"); | |
return; | |
} | |
counter++; | |
} | |
void OnTriggerEnter(Collider other) | |
{ | |
Debug.Log("FireWall OnTriggerEnter="+ other.name + ", tag=" + other.tag); | |
switch (other.tag) | |
{ | |
case "Bomb": | |
// 爆弾に当たった | |
Debug.Log("FireWall Hit Bomb"); | |
bStop = true; | |
break; | |
case "Player": // = CameraRig | |
// プレイヤーに当たった | |
Debug.Log("FireWall Hit Player"); | |
break; | |
default: | |
bStop = true; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment