有一个敌人从它附加的FireballBox对象发射火球,火球的发射是通过调用预制件实现的。一切似乎都正常,球会正常飞行,但如果敌人向左或向右转 90 度(一直注视着玩家),那么火球就会变形,宽度会愚蠢地拉伸。 Fireball 脚本附加到火球本身,而 FireballRotation 附加到 FireballBox 并负责火球的飞行路径。在第一个屏幕上有一个正常的火球,在第二个屏幕上它已经在另一个方向并且扭曲了。请帮忙,谁能遇到预制件的尺寸总是正常的。
public class Fireball : MonoBehaviour
{
public int Speed;
Vector3 lastPos;
private GameObject FBPrefab;
public GameObject arr;
[SerializeField] private float hitCooldown = 1.5f;
public float cooldown = 0;
public float attackSpeed = 1f;
// Start is called before the first frame update
void Start()
{
FBPrefab = Resources.Load("Fireball1") as GameObject;
}
// Update is called once per frame
void Update()
{
if (cooldown > -0.5)
{
cooldown -= Time.deltaTime;
}
if (cooldown <= 0)
{
//FBPrefab.transform.localScale = new Vector3(1.5, 2.5, 4.5);
GameObject newArrow = Instantiate(FBPrefab, transform.position, transform.rotation);
//newArrow.transform.position = transform.position;
//newArrow.transform.rotation = Quaternion.Euler(new Vector3(0, -180, -180));
Rigidbody rb = newArrow.GetComponent<Rigidbody>();
rb.velocity = transform.forward * Speed;
Destroy(newArrow, 2);
cooldown = hitCooldown * attackSpeed;
}
}
public void Shoot()
{
if (cooldown <= 0)
{
//FBPrefab.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 90));
GameObject newArrow = Instantiate(FBPrefab, transform.position, transform.rotation);
//newArrow.transform.rotation = Quaternion.Euler(new Vector3(0, -180, -180));
//newArrow.transform.position = transform.position;
Rigidbody rb = newArrow.GetComponent<Rigidbody>();
rb.velocity = transform.forward * Speed;
Destroy(newArrow, 2);
cooldown = hitCooldown * attackSpeed;
}
}
}
public class FireballRotation : MonoBehaviour
{
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
transform.Rotate(new Vector3(-90.0f, -90.0f, 0.0f));
}
// Update is called once per frame
void Update()
{
//transform.rotation = Quaternion.LookRotation(rb.velocity);
}
}
我找不到关于此的任何信息,我尝试了所有方法,但无法修复它。虽然即使是调用的预制件的规模也没有改变。
Unity 新手在这里,这可能没有帮助 - 但它很快。是继承问题吗?火球是隐式实例化为 FireballBox 对象的子对象,还是从中进行变换或旋转?如果更新函数继续从 FireballBox 对象为火球赋值,那么如果敌人的旋转发生变化,它就会改变,因为 FireballBox 是敌人的子对象。