| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SingleScreenBorder : MonoBehaviour
- {
- public ScreenCrash sc;
- [Header("是否可生效")]
- public bool canAffect;
- [Header("挂载的对象是哪个边界")]
- public bool isUp;
- public bool isDown;
- public bool isLeft;
- public bool isRight;
- private void JudgeCanRebound(Enemy ene)
- {
- if (!ene.isBeBlownUp)
- {
- return;
- }
- Vector3 vel = ene.rb.velocity;
- if (isLeft && vel.x < 0 || isRight && vel.x > 0)
- {
- Vector3 force = sc.forceX;
- if (!isLeft)
- {
- force.x = -force.x;
- }
- ene.isBeReboundedX = true;
- ene.BeHit(ene.wallDamage);
- return;
- }
- if (isUp && vel.y > 0 || isDown && vel.y < 0)
- {
- ene.isBeReboundedY = true;
- ene.BeHit(ene.wallDamage);
- return;
- }
- return;
- }
- private void OnTriggerEnter(Collider other)
- {
- if (canAffect && other.gameObject.layer == 8)
- {
- Enemy e = other.GetComponentInParent<Enemy>();
- JudgeCanRebound(e);
- }
- }
- }
|