hi all,
i’m starting programing, sorry if its an easy issue.
i have a problem whit my script.
If i press right arrow i can shoot.
If i press left arrow i can shoot.
if i press up and right arrow i can shoot…
but i i press up and left arrow, down and left, down and right i can’t shoot.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField] private float _impulse= 5.0f;
[SerializeField] private float _rotspeed = 2.0f;
[SerializeField] private float _maxSpeed = 8.0f;
public GameObject laserPrefab;
private Rigidbody playerRb;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent();
}
// Update is called once per frame
void Update()
{
Shooting();
Movement();
}
void Movement()
{
if (Input.GetKey(KeyCode.UpArrow))
{
playerRb.AddRelativeForce(Vector3.forward * _impulse * Time.deltaTime, ForceMode.Impulse);
}
if(Input.GetKey(KeyCode.DownArrow))
{
playerRb.AddRelativeForce(Vector3.back * _impulse * Time.deltaTime, ForceMode.Impulse);
}
transform.Rotate(0.0f, Input.GetAxis(“Horizontal”) * _rotspeed, 0.0f);
playerRb.velocity = Vector3.ClampMagnitude(playerRb.velocity, _maxSpeed);
}
void Shooting()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(laserPrefab, gameObject.transform.localPosition, gameObject.transform.rotation);
}
}
}