老虎普工
This commit is contained in:
parent
f7a42f94ab
commit
842d9b9770
@ -129,6 +129,7 @@ public class Attack : MonoBehaviour
|
||||
|
||||
public void GetAllColliderInAttackRange(Collider2D[] colliders)
|
||||
{
|
||||
|
||||
for (int i=0;i<colliders.Length;i++)
|
||||
{
|
||||
Role targetRole = colliders[i].GetComponent<Role>();
|
||||
@ -146,18 +147,26 @@ public class Attack : MonoBehaviour
|
||||
}
|
||||
else if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying|| bulletPrefab.GetComponent<Bullet>().myBulletType==BulletType.XuLi)
|
||||
{
|
||||
if (i==0&&animator.transform.position.x > colliders[i].transform.position.x)
|
||||
if (animator.GetInteger("State")==0)
|
||||
{
|
||||
dir = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = 1;
|
||||
}
|
||||
if (animator.transform.position.x > colliders[i].transform.position.x)
|
||||
{
|
||||
dir = -1;
|
||||
animator.transform.rotation = Quaternion.Euler(0, 180, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = 1;
|
||||
animator.transform.rotation = Quaternion.Euler(0, 0, 0);
|
||||
}
|
||||
|
||||
animator.transform.localScale = new Vector3(animator.transform.localScale.x*dir, animator.transform.localScale.y, animator.transform.localScale.z);
|
||||
animator.SetInteger("State", 1);
|
||||
flag = true;
|
||||
|
||||
|
||||
//animator.transform.localScale = new Vector3(animator.transform.localScale.x * dir, animator.transform.localScale.y, animator.transform.localScale.z);
|
||||
animator.SetInteger("State", 1);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
||||
@ -221,15 +230,15 @@ public class Attack : MonoBehaviour
|
||||
switch (BulletNumber)
|
||||
{
|
||||
case 1:
|
||||
// 生成一个不旋转的子弹
|
||||
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0));
|
||||
// 生成一个不旋转的子
|
||||
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0),dir);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// 生成三个子弹:一个不旋转,一个向上旋转30度,一个向下旋转30度
|
||||
GenerateBullet(-35f, BulletStartPos.position, new Vector2(0, -0.25f));
|
||||
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0));
|
||||
GenerateBullet(35f, BulletStartPos.position, new Vector2(0, 0.25f));
|
||||
GenerateBullet(-35f, BulletStartPos.position, new Vector2(0, -0.25f),dir);
|
||||
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0),dir);
|
||||
GenerateBullet(35f, BulletStartPos.position, new Vector2(0, 0.25f),dir);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -241,11 +250,12 @@ public class Attack : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)
|
||||
private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos,int dir)
|
||||
{
|
||||
// 实例化子弹对象并设置父物体为 transform.root
|
||||
GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root);
|
||||
|
||||
bulletGameObj.transform.localScale = new Vector2(bulletGameObj.transform.localScale.x*dir, bulletGameObj.transform.localScale.y);
|
||||
// 获取子弹的原始宽度
|
||||
float originalWidth = bulletGameObj.GetComponentInChildren<SpriteRenderer>().bounds.size.x;
|
||||
|
||||
@ -275,14 +285,14 @@ public class Attack : MonoBehaviour
|
||||
offsetX = (newWidth - originalWidth) / 2;
|
||||
if (offsetX > 0)
|
||||
{
|
||||
offsetX += 0.15f;
|
||||
offsetX += 0.15f*dir;
|
||||
}
|
||||
// 调整子弹的位置,确保左边界不变
|
||||
bulletGameObj.transform.position = new Vector2(originalPosition.x + offsetX, originalPosition.y);
|
||||
}
|
||||
|
||||
// 添加位置微调
|
||||
bulletGameObj.transform.position = new Vector2(bulletGameObj.transform.position.x + 1.75f, bulletGameObj.transform.position.y + 0.2f);
|
||||
bulletGameObj.transform.position = new Vector2(bulletGameObj.transform.position.x + 1.75f*dir, bulletGameObj.transform.position.y + 0.2f);
|
||||
|
||||
// 获取动画组件(如果需要的话)
|
||||
fireAnis.Add(bulletGameObj.GetComponentInChildren<Animator>());
|
||||
@ -310,7 +320,8 @@ public class Attack : MonoBehaviour
|
||||
bulltes.Add(bulletGameObj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void EndFire()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user