我的游戏中存在以下问题;
当我向对手射击时,随着射线投射命中,他的旋转角度为Y角,因此我将角色旋转90度,因此可以按照代码中的直线对他射击:
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.tag == "Espantalho" || hit.transform.tag == "Xama" || hit.transform.tag == "Sheriff")
{
//instantiates the bullet
GameObject tiro = Instantiate(projetil, SpawBala.transform.position, SpawBala.transform.rotation);
Rigidbody BalaRigid = tiro.GetComponent<Rigidbody>();
tiro.transform.LookAt(hit.transform.position);
float AngleY = hit.collider.gameObject.transform.rotation.eulerAngles.y;
if (AngleY == 180 && !Girou)
{
player.transform.Rotate(0f, 90f, 0f);
Girou = true;
}
if (Girou)
{
player.transform.Rotate(0f, 0f, 0f);
}
BalaRigid.velocity = SpawBala.transform.forward * ProjetilVeloc * Time.deltaTime;
gameManager.PontoAcaop1--;
Personagens[i].GetComponent<Jogador>().PodeAtacar = true;
interfaceManager.ActionPointDown();
}
}
但是这种情况不起作用,因为我的角色不会旋转回原来的位置。我做错了什么人?
if (Girou)
{
player.transform.Rotate(0f, 0f, 0f);
}