2021-07-08 19:52:46 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Shell : MonoBehaviour
|
|
|
|
{
|
2021-08-07 01:31:29 +08:00
|
|
|
//炮弹类,控制轰炸区内的炮弹和炮弹的阴影🎇
|
2021-07-08 19:52:46 +08:00
|
|
|
// Start is called before the first frame update
|
|
|
|
public GameObject shadow;//阴影游戏物体
|
|
|
|
private Transform ground;//地面的位置信息
|
|
|
|
private float shellSpeed;//炮弹速度
|
|
|
|
private IndexRecoder indexRecoder;
|
|
|
|
private float fallingTime;
|
|
|
|
private bool isDroping = false;
|
|
|
|
private Transform m_shadow;
|
2021-07-08 22:58:46 +08:00
|
|
|
public GameObject boomObj;
|
2021-08-18 00:50:19 +08:00
|
|
|
public BombingArea M_BombingArea;
|
|
|
|
private bool amISpecal = false;//记录自己是不是特殊的的变量。特殊的炮弹才能炸烂石头。
|
2021-07-08 22:58:46 +08:00
|
|
|
|
2021-07-08 19:52:46 +08:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
indexRecoder = FindObjectOfType<IndexRecoder>();
|
|
|
|
shellSpeed = indexRecoder.shellSpeed;
|
|
|
|
fallingTime = indexRecoder.shellFallingTime;
|
|
|
|
ground = GameObject.FindWithTag("地面").transform;
|
|
|
|
m_shadow = Instantiate(shadow,//生成一片阴影
|
|
|
|
new Vector3(transform.position.x,//在这枚炮弹的X
|
|
|
|
ground.transform.position.y + //地面的Y
|
2021-08-18 00:50:19 +08:00
|
|
|
M_BombingArea.shellShadowYOffset,//加上偏移量
|
2021-07-08 19:52:46 +08:00
|
|
|
0),
|
|
|
|
Quaternion.identity)
|
|
|
|
.transform;
|
|
|
|
Invoke("Drop",fallingTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
ShadowShock();
|
|
|
|
if(isDroping)
|
|
|
|
{
|
|
|
|
transform.position -= new Vector3(0,shellSpeed*Time.deltaTime,0);
|
|
|
|
}
|
2021-07-08 22:58:46 +08:00
|
|
|
|
|
|
|
|
2021-07-08 19:52:46 +08:00
|
|
|
}
|
|
|
|
|
2021-08-18 00:50:19 +08:00
|
|
|
public bool AmISpecal(){return amISpecal;}//外部调用,返回这个炮弹是不是特殊的
|
|
|
|
public void YouAreSpecal(){amISpecal = true;}//外部调用,生成炮弹时,给其标记它是特殊的。
|
|
|
|
|
2021-07-08 19:52:46 +08:00
|
|
|
private void ShadowShock()
|
|
|
|
{
|
|
|
|
m_shadow.transform.localScale = new Vector3(m_shadow.localScale.x +
|
|
|
|
Random.Range(-indexRecoder.shellShadowRangeOfChange,
|
|
|
|
indexRecoder.shellShadowRangeOfChange),
|
|
|
|
m_shadow.localScale.y,
|
|
|
|
m_shadow.localScale.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Drop()
|
|
|
|
{
|
|
|
|
isDroping = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
|
|
{
|
2021-07-18 23:58:09 +08:00
|
|
|
//Debug.Log(other.name);
|
2021-07-08 19:52:46 +08:00
|
|
|
//当玩家被炮弹击中
|
|
|
|
switch (other.tag)
|
|
|
|
{
|
|
|
|
case "Player":
|
|
|
|
//玩家被炮弹击中
|
|
|
|
break;
|
|
|
|
case "地面":
|
|
|
|
Destroy(m_shadow.gameObject);
|
|
|
|
Destroy(gameObject);
|
2021-07-08 22:58:46 +08:00
|
|
|
Instantiate(boomObj, new Vector2(transform.position.x, transform.position.y),Quaternion.identity);
|
2021-07-08 19:52:46 +08:00
|
|
|
break;
|
2021-08-18 00:50:19 +08:00
|
|
|
case "石头":
|
|
|
|
Destroy(m_shadow.gameObject);
|
|
|
|
Destroy(gameObject);//摧毁炮弹
|
|
|
|
//如果自己是特殊的炮弹,则触发石头的程序段
|
|
|
|
if(amISpecal) other.GetComponent<Stone>().BeHitBySpecalShell();
|
|
|
|
break;
|
2021-07-08 19:52:46 +08:00
|
|
|
}
|
|
|
|
}
|
2021-07-08 22:58:46 +08:00
|
|
|
|
2021-07-08 19:52:46 +08:00
|
|
|
|
|
|
|
}
|