子弹特效
This commit is contained in:
parent
5a778abdbc
commit
4d4a9e5b0b
@ -13,6 +13,17 @@ public enum BulletType
|
||||
Spraying //原地喷射
|
||||
|
||||
}
|
||||
public enum BulletAttributes
|
||||
{
|
||||
Not,
|
||||
Gold,//金木水火土
|
||||
Wood,
|
||||
Water,
|
||||
Fire,
|
||||
Earth
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum BulletMoveType
|
||||
{/// <summary>
|
||||
@ -40,6 +51,7 @@ public class BulletData
|
||||
[Header("子弹飞行速度")] public float BulletSpeed = 5f;
|
||||
[Header("子弹攻击冷却")] public float BulletAttackCooldown = 1f;
|
||||
[Header("子弹伤害")] public float attack = 10;
|
||||
|
||||
public BulletData()
|
||||
{
|
||||
|
||||
@ -66,9 +78,14 @@ public class Bullet : MonoBehaviour
|
||||
[Header("子弹发射角色对象")] public Role role;
|
||||
[Header("子弹发射范围对象")] public Attack attackObj;
|
||||
[Header("子弹类型")] public BulletType myBulletType;
|
||||
[Header("子弹属性")] public BulletAttributes bulletAttributes;
|
||||
[Header("攻击类型")] public BulletMoveType bulletMoveType;
|
||||
[Header("子弹数据")] public BulletData bulletData = new BulletData();
|
||||
[Header("销毁时间,默认是10f")] public float BulletDeadTimer=10f;
|
||||
[Header("子弹动画")] public Animator animator;
|
||||
[Header("子弹移动参数")] public bool IsMove=true;
|
||||
[Header("子弹碰撞体")] public Collider2D Collider2D;
|
||||
[Header("子弹特效预制体")] public GameObject effectPre;
|
||||
private float timer = 0;
|
||||
private void Update()
|
||||
{
|
||||
@ -76,14 +93,18 @@ public class Bullet : MonoBehaviour
|
||||
{
|
||||
//更具子弹的移动方式来移动
|
||||
case BulletMoveType.PeerToPeer:
|
||||
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
|
||||
timer += Time.deltaTime;
|
||||
if (timer > BulletDeadTimer)
|
||||
if (IsMove)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
|
||||
timer += Time.deltaTime;
|
||||
if (timer > BulletDeadTimer)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case BulletMoveType.PointToDirection:
|
||||
break;
|
||||
@ -112,13 +133,37 @@ public class Bullet : MonoBehaviour
|
||||
|
||||
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role },direction);
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
|
||||
|
||||
if (myBulletType!=BulletType.Spraying)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
IsMove = false;//停止移动
|
||||
Collider2D.enabled = false;//关闭碰撞体
|
||||
transform.position = collision.transform.position;
|
||||
animator.SetTrigger("Boom");
|
||||
Debug.Log("爆炸动画+++++++++++++++++++++++++++++++++");
|
||||
}
|
||||
}
|
||||
|
||||
if (bulletAttributes==BulletAttributes.Fire)
|
||||
{
|
||||
if (effectPre!=null)
|
||||
{
|
||||
Instantiate(effectPre, collision.transform).transform.position=new Vector2(collision.transform.position.x, collision.transform.position.y+0.2f);
|
||||
|
||||
Debug.Log("创建火焰");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,6 +199,12 @@ public class Bullet : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void DesBullet()
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
@ -167,8 +218,15 @@ public class Bullet : MonoBehaviour
|
||||
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
if (myBulletType != BulletType.Spraying)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Destroy(this.gameObject);
|
||||
if (animator==null)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user