I am creating a 3D Game in unity where you are a Space ship shooting projectiles, I want to make it so when I pick up an powerUp to change the style of shooting, and for that I created another 2 bullets with different scripts for the bullet that should go oblique on the left side and the one that should go oblique right.
I created a prefab of those two and when I shoot they are not moving oblique but only on the x axis.
如果我只有一个子弹,它是工作的,但当我添加第二个子弹时,它只在x轴上移动,而不是在x和y轴上移动.
这是正在工作的子弹和右侧倾斜的子弹以及这两个不起作用的子弹的代码:
public class laser_Right : MonoBehaviour
{
public int speed = 8;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Movelaser();
}
void Movelaser()
{
Vector3 movement = (Vector3.up + Vector3.right).normalized * speed * Time.deltaTime;
transform.Translate(movement);
if (transform.position.y >= 9)
{
Destroy(gameObject);
}
}
}
因为左边的子弹是一样的,但是方向不同.
我很确定代码是正确的,但问题出在其他地方,可能是因为我用两颗子弹制作了一个预制件? 子弹设计了不同的 playbook ,所以我不明白为什么它不起作用.